2

I have a question regarding VerifySeal function in Geth source code. If I understood correctly, it verifies if block has valid seal regarding the PoW algorithm. The arguments that function takes are chainReader and block header. Is there a way to get the body of the block that is being verified? I know that chainReader has method GetBlock(), but it needs the hash of the block and I don't know how to obtain it. On the other hand, I'm not sure if the block that is being verified is on the blockhain yet, so perhaps this method won't even work?

2

Q1: I have a question regarding VerifySeal function in Geth source code. If I understood correctly, it verifies if block has valid seal regarding the PoW algorithm. The arguments that function takes are chainReader and block header. Is there a way to get the body of the block that is being verified? I know that chainReader has method GetBlock(), but it needs the hash of the block and I don't know how to obtain it

As code comment, you can see that the VerifySeal() only verify the header including the nonce of PoW algorithm as you mentioned. So getting block body is not necessary for this method.

// VerifySeal checks whether the crypto seal on a header is valid according to
// the consensus rules of the given engine.
VerifySeal(chain ChainReader, header *types.Header) error

full block data need when sealing as in below Seal() method; because it need to calculate the merkle tree root hash transactionsRoot for all the transactions in the block.

// Seal generates a new block for the given input block with the local miner's
// seal place on top.
Seal(chain ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)

Q2: On the other hand, I'm not sure if the block that is being verified is on the blockhain yet, so perhaps this method won't even work?

When a node receive block from a remote node, it need to verify all the things such as block header, block body and it replay all the transactions in the block to validate the state as well. You can find more detail by drill down into github.com/ethereum/go-ethereum/core/blockchain.go source code

// insertChain will execute the actual chain insertion and event aggregation. The
// only reason this method exists as a separate one is to make locking cleaner
// with deferred statements.
func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*types.Log, error)

Hope this will help!

| improve this answer | |
  • Thanks for ansewrs. I have another regarding Q1. Aren't transactions neccesary for calculating seal when mining (and thus verifying)? The comments are clear, but it seems that I missed something. Thanks again. – Milan Todorovic Sep 16 '18 at 7:27
  • When block sealing, transactions are necessary. because the limitation of comment then I updated the answer. PTAL. – Ha ĐANG Sep 16 '18 at 14:49
  • Thank you for answering. I still have a question, though (thanks for helping me). I fail to see where are those roots crated. I'm looking at sealer.go file. I only see header used for sealing (Seal and mine methods). Obviously, I'm missing something... Also, the root that you are refering to is TxHash field in header? – Milan Todorovic Sep 17 '18 at 9:19
  • yes, it's the TxHash in the source code – Ha ĐANG Sep 17 '18 at 9:20
  • So it is enough to have header with TxHash to calculate nonce? – Milan Todorovic Sep 17 '18 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.