Documentation ¶
Index ¶
- Variables
- func NewDummyGossip(t *testing.T) gossip.Gossip
- func NewDummyP2P(t *testing.T) p2p.P2P
- func NewSimpleState(t *testing.T, opts ...state.Opt) state.State
- type DummyEngine
- type DummyPoW
- type DummyProcessor
- type DummyProofOfWait
- type DummyValidator
- func (v *DummyValidator) MaxTxPerBlock() uint32
- func (v *DummyValidator) ValidateBlock(block *pb.Block, _ state.Reader) error
- func (v *DummyValidator) ValidateTransactions(transactions []*pb.Transaction, _ state.Reader) error
- func (v *DummyValidator) ValidateTx(tx *pb.Transaction, state state.Reader) error
- type FaultyEngine
- type FaultyProcessor
- type HeaderMatcher
- type InMemoryTxPool
- func (m *InMemoryTxPool) AddTransaction(tx *pb.Transaction) error
- func (m *InMemoryTxPool) Contains(tx *pb.Transaction) bool
- func (m *InMemoryTxPool) Peek(n uint32) []*pb.Transaction
- func (m *InMemoryTxPool) Pending() uint64
- func (m *InMemoryTxPool) PopCount() uint32
- func (m *InMemoryTxPool) PopTransaction() *pb.Transaction
- func (m *InMemoryTxPool) TxCount() int
- type InstrumentedEngine
- func (e *InstrumentedEngine) Finalize(ctx context.Context, chain chain.Reader, header *pb.Header, state state.Reader, ...) (*pb.Block, error)
- func (e *InstrumentedEngine) FinalizeCount() uint32
- func (e *InstrumentedEngine) Prepare(chain chain.Reader, header *pb.Header) error
- func (e *InstrumentedEngine) PrepareCount() uint32
- func (e *InstrumentedEngine) VerifiedHeader(header *pb.Header) bool
- func (e *InstrumentedEngine) VerifyCount() uint32
- func (e *InstrumentedEngine) VerifyHeader(chain chain.Reader, header *pb.Header) error
- type InstrumentedProcessor
- type InstrumentedValidator
- func (r *InstrumentedValidator) MaxTxPerBlock() uint32
- func (r *InstrumentedValidator) ValidateBlock(block *pb.Block, state state.Reader) error
- func (r *InstrumentedValidator) ValidateTransactions(transactions []*pb.Transaction, state state.Reader) error
- func (r *InstrumentedValidator) ValidateTx(tx *pb.Transaction, state state.Reader) error
- func (r *InstrumentedValidator) ValidatedBlock(block *pb.Block) bool
- func (r *InstrumentedValidator) ValidatedTx(tx *pb.Transaction) bool
- type Rejector
- type SimpleChain
- func (c *SimpleChain) AddBlock(block *pb.Block) error
- func (c *SimpleChain) Config() *chain.Config
- func (c *SimpleChain) CurrentBlock() (*pb.Block, error)
- func (c *SimpleChain) CurrentHeader() (*pb.Header, error)
- func (c *SimpleChain) GetBlock(hash []byte, _ uint64) (*pb.Block, error)
- func (c *SimpleChain) GetBlockByHash(hash []byte) (*pb.Block, error)
- func (c *SimpleChain) GetBlockByNumber(number uint64) (*pb.Block, error)
- func (c *SimpleChain) GetHeaderByHash(hash []byte) (*pb.Header, error)
- func (c *SimpleChain) GetHeaderByNumber(number uint64) (*pb.Header, error)
- func (c *SimpleChain) GetHeadersByNumber(number uint64) ([]*pb.Header, error)
- func (c *SimpleChain) GetParentBlock(header *pb.Header) (*pb.Block, error)
- func (c *SimpleChain) SetHead(block *pb.Block) error
- type TxMatcher
Constants ¶
This section is empty.
Variables ¶
var ErrFaultyEngine = errors.New("unknown error: engine must be faulty")
ErrFaultyEngine is the error returned by a FaultyEngine.
var ErrProcessingFailed = errors.New("processing failed")
ErrProcessingFailed is the error returned by FaultyProcessor.
var ( // ErrRejected is the error returns by Rejector. ErrRejected = errors.New("rejected") )
Functions ¶
func NewDummyGossip ¶
NewDummyGossip returns a gossip mock that does nothing.
func NewDummyP2P ¶
NewDummyP2P returns a p2p mock that does nothing.
Types ¶
type DummyEngine ¶
type DummyEngine struct{}
DummyEngine is an engine that does nothing.
func (*DummyEngine) Finalize ¶
func (e *DummyEngine) Finalize(ctx context.Context, chain chain.Reader, header *pb.Header, state state.Reader, txs []*pb.Transaction) (*pb.Block, error)
Finalize returns an empty block with the given header.
func (*DummyEngine) VerifyHeader ¶
VerifyHeader does nothing.
type DummyPoW ¶
type DummyPoW struct { InstrumentedEngine // contains filtered or unexported fields }
DummyPoW is a dummy proof-of-work engine.
func NewDummyPoW ¶
NewDummyPoW creates a new DummyPoW.
func (*DummyPoW) Difficulty ¶
Difficulty returns a configurable difficulty.
func (*DummyPoW) DifficultyCount ¶
DifficultyCount returns the number of calls to Difficulty.
type DummyProcessor ¶
type DummyProcessor struct{}
DummyProcessor is a dummy processor that always returns nil as if processing ended correctly.
type DummyProofOfWait ¶
type DummyProofOfWait struct { InstrumentedEngine // contains filtered or unexported fields }
DummyProofOfWait is a dummy proof-of-wait © engine.
func NewDummyProofOfWait ¶
func NewDummyProofOfWait(e engine.Engine, min, max int) *DummyProofOfWait
NewDummyProofOfWait creates a new DummyProofOfWait.
func (*DummyProofOfWait) Interval ¶
func (e *DummyProofOfWait) Interval() (int, int)
Interval increments a counter and returns a configurable interval for the proof-of-wait.
func (*DummyProofOfWait) IntervalCount ¶
func (e *DummyProofOfWait) IntervalCount() uint32
IntervalCount returns the number of calls to Interval.
type DummyValidator ¶
type DummyValidator struct{}
DummyValidator is a validator that always returns nil (valid).
func (*DummyValidator) MaxTxPerBlock ¶
func (v *DummyValidator) MaxTxPerBlock() uint32
MaxTxPerBlock always returns 1.
func (*DummyValidator) ValidateBlock ¶
ValidateBlock always returns nil (valid block).
func (*DummyValidator) ValidateTransactions ¶
func (v *DummyValidator) ValidateTransactions(transactions []*pb.Transaction, _ state.Reader) error
ValidateTransactions always returns nil (valid block).
func (*DummyValidator) ValidateTx ¶
func (v *DummyValidator) ValidateTx(tx *pb.Transaction, state state.Reader) error
ValidateTx always returns nil (valid tx).
type FaultyEngine ¶
type FaultyEngine struct{}
FaultyEngine always returns an ErrFaultyEngine error.
func (*FaultyEngine) Finalize ¶
func (e *FaultyEngine) Finalize(ctx context.Context, chain chain.Reader, header *pb.Header, state state.Reader, txs []*pb.Transaction) (*pb.Block, error)
Finalize does nothing.
func (*FaultyEngine) VerifyHeader ¶
VerifyHeader records that header was verified.
type FaultyProcessor ¶
type FaultyProcessor struct{}
FaultyProcessor is a dummy processor that always returns an error as if processing failed.
type HeaderMatcher ¶
type HeaderMatcher struct {
// contains filtered or unexported fields
}
HeaderMatcher matches headers.
func NewHeaderMatcher ¶
func NewHeaderMatcher(expectedHeader *pb.Header) HeaderMatcher
NewHeaderMatcher creates a HeaderMatcher.
func (HeaderMatcher) Matches ¶
func (m HeaderMatcher) Matches(x interface{}) bool
Matches returns whether x is a match. For unit tests, matching on block number should be enough.
func (HeaderMatcher) String ¶
func (m HeaderMatcher) String() string
String describes what the matcher matches.
type InMemoryTxPool ¶
type InMemoryTxPool struct {
// contains filtered or unexported fields
}
InMemoryTxPool is a basic txpool implementation that stores transactions in RAM.
func (*InMemoryTxPool) AddTransaction ¶
func (m *InMemoryTxPool) AddTransaction(tx *pb.Transaction) error
AddTransaction adds transaction to the txpool.
func (*InMemoryTxPool) Contains ¶
func (m *InMemoryTxPool) Contains(tx *pb.Transaction) bool
Contains returns true if the txpool contains the given transaction.
func (*InMemoryTxPool) Peek ¶
func (m *InMemoryTxPool) Peek(n uint32) []*pb.Transaction
Peek returns the n first transactions from the pool.
func (*InMemoryTxPool) Pending ¶
func (m *InMemoryTxPool) Pending() uint64
Pending returns the number of transactions.
func (*InMemoryTxPool) PopCount ¶
func (m *InMemoryTxPool) PopCount() uint32
PopCount returns the number of times PopTransaction was called.
func (*InMemoryTxPool) PopTransaction ¶
func (m *InMemoryTxPool) PopTransaction() *pb.Transaction
PopTransaction pops the oldest transaction from the txpool.
func (*InMemoryTxPool) TxCount ¶
func (m *InMemoryTxPool) TxCount() int
TxCount returns the number of transactions in the txpool.
type InstrumentedEngine ¶
type InstrumentedEngine struct {
// contains filtered or unexported fields
}
InstrumentedEngine adds method calls instrumentation to an engine.
func NewInstrumentedEngine ¶
func NewInstrumentedEngine(e engine.Engine) *InstrumentedEngine
NewInstrumentedEngine wraps an engine with instrumentation.
func (*InstrumentedEngine) Finalize ¶
func (e *InstrumentedEngine) Finalize(ctx context.Context, chain chain.Reader, header *pb.Header, state state.Reader, txs []*pb.Transaction) (*pb.Block, error)
Finalize records the call.
func (*InstrumentedEngine) FinalizeCount ¶
func (e *InstrumentedEngine) FinalizeCount() uint32
FinalizeCount returns the number of calls to Finalize.
func (*InstrumentedEngine) PrepareCount ¶
func (e *InstrumentedEngine) PrepareCount() uint32
PrepareCount returns the number of calls to Prepare.
func (*InstrumentedEngine) VerifiedHeader ¶
func (e *InstrumentedEngine) VerifiedHeader(header *pb.Header) bool
VerifiedHeader checks if the input header was verified by the engine.
func (*InstrumentedEngine) VerifyCount ¶
func (e *InstrumentedEngine) VerifyCount() uint32
VerifyCount returns the number of calls to VerifyHeader.
func (*InstrumentedEngine) VerifyHeader ¶
VerifyHeader records that header was verified.
type InstrumentedProcessor ¶
type InstrumentedProcessor struct {
// contains filtered or unexported fields
}
InstrumentedProcessor adds method calls instrumentation to a processor.
func NewInstrumentedProcessor ¶
func NewInstrumentedProcessor(p processor.Processor) *InstrumentedProcessor
NewInstrumentedProcessor wraps a processor with instrumentation.
func (*InstrumentedProcessor) Process ¶
func (p *InstrumentedProcessor) Process(ctx context.Context, block *pb.Block, state state.State, chain chain.Chain) error
Process records the call.
func (*InstrumentedProcessor) ProcessedCount ¶
func (p *InstrumentedProcessor) ProcessedCount() uint32
ProcessedCount returns the number of blocks processed.
type InstrumentedValidator ¶
type InstrumentedValidator struct {
// contains filtered or unexported fields
}
InstrumentedValidator adds method calls instrumentation to a validator.
func NewInstrumentedValidator ¶
func NewInstrumentedValidator(validator validator.Validator) *InstrumentedValidator
NewInstrumentedValidator wraps a validator with instrumentation.
func (*InstrumentedValidator) MaxTxPerBlock ¶
func (r *InstrumentedValidator) MaxTxPerBlock() uint32
MaxTxPerBlock returns the maximum number of transactions allowed in a block.
func (*InstrumentedValidator) ValidateBlock ¶
ValidateBlock records the incoming block.
func (*InstrumentedValidator) ValidateTransactions ¶
func (r *InstrumentedValidator) ValidateTransactions(transactions []*pb.Transaction, state state.Reader) error
ValidateTransactions records the incoming block.
func (*InstrumentedValidator) ValidateTx ¶
func (r *InstrumentedValidator) ValidateTx(tx *pb.Transaction, state state.Reader) error
ValidateTx records the incoming tx.
func (*InstrumentedValidator) ValidatedBlock ¶
func (r *InstrumentedValidator) ValidatedBlock(block *pb.Block) bool
ValidatedBlock returns true if the validator saw the given block.
func (*InstrumentedValidator) ValidatedTx ¶
func (r *InstrumentedValidator) ValidatedTx(tx *pb.Transaction) bool
ValidatedTx returns true if the validator saw the given transaction.
type Rejector ¶
type Rejector struct{}
Rejector implements the Validator interface and rejects incoming transactions and blocks.
func (*Rejector) MaxTxPerBlock ¶
MaxTxPerBlock always returns 1.
func (*Rejector) ValidateBlock ¶
ValidateBlock records the incoming block and rejects it.
func (*Rejector) ValidateTransactions ¶
ValidateTransactions records the incoming block and rejects it.
func (*Rejector) ValidateTx ¶
ValidateTx records the incoming tx and rejects it.
type SimpleChain ¶
type SimpleChain struct {
// contains filtered or unexported fields
}
SimpleChain can be used in tests to inject arbitrary blocks.
func (*SimpleChain) AddBlock ¶
func (c *SimpleChain) AddBlock(block *pb.Block) error
AddBlock adds a block to the chain without any validation. It also sets the given block as current block.
func (*SimpleChain) CurrentBlock ¶
func (c *SimpleChain) CurrentBlock() (*pb.Block, error)
CurrentBlock returns the header of the last block added.
func (*SimpleChain) CurrentHeader ¶
func (c *SimpleChain) CurrentHeader() (*pb.Header, error)
CurrentHeader returns the header of the last block added.
func (*SimpleChain) GetBlockByHash ¶
func (c *SimpleChain) GetBlockByHash(hash []byte) (*pb.Block, error)
GetBlockByHash returns the first block with the given header hash.
func (*SimpleChain) GetBlockByNumber ¶
func (c *SimpleChain) GetBlockByNumber(number uint64) (*pb.Block, error)
GetBlockByNumber retrieves a header from the main branch by number.
func (*SimpleChain) GetHeaderByHash ¶
func (c *SimpleChain) GetHeaderByHash(hash []byte) (*pb.Header, error)
GetHeaderByHash returns the first header of the block with the given hash.
func (*SimpleChain) GetHeaderByNumber ¶
func (c *SimpleChain) GetHeaderByNumber(number uint64) (*pb.Header, error)
GetHeaderByNumber retrieves a header from the main branch by number.
func (*SimpleChain) GetHeadersByNumber ¶
func (c *SimpleChain) GetHeadersByNumber(number uint64) ([]*pb.Header, error)
GetHeadersByNumber returns all headers that have the input BlockNumber.
func (*SimpleChain) GetParentBlock ¶
GetParentBlock retrieves the block's parent block.
type TxMatcher ¶
type TxMatcher struct {
// contains filtered or unexported fields
}
TxMatcher matches transactions.
func NewTxMatcher ¶
func NewTxMatcher(expectedTx *pb.Transaction) TxMatcher
NewTxMatcher creates a TxMatcher.