Skip to content

Commit

Permalink
[Blockchain] Simplify block verification (#544)
Browse files Browse the repository at this point in the history
* Add the initial block verification separation

* Separate out consensus and other module verification methods

* Add better naming to block verification methods

* Standardize block result errors

* Add receipts extraction

* Add additional documentation for the usage of the receipts cache

* Add delegators for testing the blockchain module

* Add mock support for the blockchain and storage modules

* Add coverage tests

* Simplify the gas verification

* Rearrange code blocks

* Rename some helper methods to be more clear

* Make the mock testing structure public, refactor a simple test

* Remove redundant comment

* Simplify the error variable in initCaches

* Eliminate magic numbers

* Rearrange the checks in VerifySealedBlock

* Remove reference block type when verifying

* Add explainer for WriteBlock

* Verify the header seals before inserting the block

* Rename interface methods to be more implementation agnostic
  • Loading branch information
zivkovicmilos committed Jun 1, 2022
1 parent cad2fb2 commit 06dc155
Show file tree
Hide file tree
Showing 15 changed files with 1,170 additions and 241 deletions.
5 changes: 5 additions & 0 deletions archive/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type blockchainInterface interface {
GetBlockByNumber(uint64, bool) (*types.Block, bool)
GetHashByNumber(uint64) types.Hash
WriteBlock(*types.Block) error
VerifyFinalizedBlock(*types.Block) error
}

// RestoreChain reads blocks from the archive and write to the chain
Expand Down Expand Up @@ -73,6 +74,10 @@ func importBlocks(chain blockchainInterface, blockStream *blockStream, progressi
nextBlock := firstBlock

for {
if err := chain.VerifyFinalizedBlock(nextBlock); err != nil {
return err
}

if err := chain.WriteBlock(nextBlock); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions archive/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (m *mockChain) WriteBlock(block *types.Block) error {
return nil
}

func (m *mockChain) VerifyFinalizedBlock(block *types.Block) error {
return nil
}

func (m *mockChain) SubscribeEvents() blockchain.Subscription {
return protocol.NewMockSubscription()
}
Expand Down
Loading

0 comments on commit 06dc155

Please sign in to comment.