type Protocoler interface {
Name() string
- Status() (uint64, *bc.Hash)
- ValidateBlock(block *bc.Block) error
- ValidateTxs(txs []*bc.Tx) error
+ BeforeProposalBlock(capacity int, nodeProgram []byte) ([]*types.Tx, error)
+ ChainStatus() (uint64, *bc.Hash, error)
+ ValidateBlock(block *types.Block, verifyResults []*bc.TxVerifyResult) error
+ ValidateTxs(txs []*types.Tx, verifyResults []*bc.TxVerifyResult) error
ApplyBlock(block *types.Block) error
DetachBlock(block *types.Block) error
}
return *blockHash == hash
}
+func (c *Chain) SubProtocols() []Protocoler {
+ return c.subProtocols
+}
+
// trace back to the tail of the chain from the given block header
func (c *Chain) traceLongestChainTail(blockHeader *types.BlockHeader) (*types.BlockHeader, error) {
longestTail, workQueue := blockHeader, []*types.BlockHeader{blockHeader}
}
func (c *Chain) syncProtocolStatus(subProtocol Protocoler) error {
- protocolHeight, protocolHash := subProtocol.Status()
- if protocolHeight == c.BestBlockHeight() && protocolHash == c.BestBlockHash() {
+ protocolHeight, protocolHash, err := subProtocol.ChainStatus()
+ if err != nil {
+ return errors.Wrap(err, "failed on get sub protocol status")
+ }
+
+ if protocolHeight == c.bestBlockHeader.Height && *protocolHash == c.bestBlockHeader.Hash() {
return nil
}
return errors.Wrap(err, subProtocol.Name(), "sub protocol detach block err")
}
- protocolHeight, protocolHash = subProtocol.Status()
+ protocolHeight, protocolHash, err = subProtocol.ChainStatus()
+ if err != nil {
+ return errors.Wrap(err, "failed on get sub protocol status")
+ }
}
for height := protocolHeight + 1; height <= c.BestBlockHeight(); height++ {
return errors.Wrap(err, subProtocol.Name(), "sub protocol apply block err")
}
- protocolHeight, protocolHash = subProtocol.Status()
+ protocolHeight, protocolHash, err = subProtocol.ChainStatus()
+ if err != nil {
+ return errors.Wrap(err, "failed on get sub protocol status")
+ }
+
if *protocolHash != block.Hash() {
return errors.Wrap(errors.New("sub protocol status sync err"), subProtocol.Name())
}