Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

[Blockchain/IBFT] Update snapshot after processBlock ends #482

Merged
merged 3 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Blockchain struct {

type Verifier interface {
VerifyHeader(parent, header *types.Header) error
ProcessHeaders(headers []*types.Header) error
GetBlockCreator(header *types.Header) (types.Address, error)
PreStateCommit(header *types.Header, txn *state.Transition) error
}
Expand Down Expand Up @@ -640,6 +641,11 @@ func (b *Blockchain) WriteBlock(block *types.Block) error {
return err
}

// update snapshot
if err := b.consensus.ProcessHeaders([]*types.Header{header}); err != nil {
return err
}

b.dispatchEvent(evnt)

// Update the average gas price
Expand Down
4 changes: 4 additions & 0 deletions blockchain/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ func (m *MockVerifier) VerifyHeader(parent, header *types.Header) error {
return nil
}

func (m *MockVerifier) ProcessHeaders(headers []*types.Header) error {
return nil
}

func (m *MockVerifier) GetBlockCreator(header *types.Header) (types.Address, error) {
return header.Miner, nil
}
Expand Down
3 changes: 3 additions & 0 deletions consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type Consensus interface {
// VerifyHeader verifies the header is correct
VerifyHeader(parent, header *types.Header) error

// ProcessHeaders updates the snapshot based on the verified headers
ProcessHeaders(headers []*types.Header) error

// GetBlockCreator retrieves the block creator (or signer) given the block header
GetBlockCreator(header *types.Header) (types.Address, error)

Expand Down
4 changes: 4 additions & 0 deletions consensus/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func (d *Dev) VerifyHeader(parent *types.Header, header *types.Header) error {
return nil
}

func (d *Dev) ProcessHeaders(headers []*types.Header) error {
return nil
}

func (d *Dev) GetBlockCreator(header *types.Header) (types.Address, error) {
return header.Miner, nil
}
Expand Down
4 changes: 4 additions & 0 deletions consensus/dummy/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ func (d *Dummy) VerifyHeader(parent *types.Header, header *types.Header) error {
return nil
}

func (d *Dummy) ProcessHeaders(headers []*types.Header) error {
return nil
}

func (d *Dummy) GetBlockCreator(header *types.Header) (types.Address, error) {
return header.Miner, nil
}
Expand Down
10 changes: 5 additions & 5 deletions consensus/ibft/ibft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1255,14 +1255,14 @@ func (i *Ibft) VerifyHeader(parent, header *types.Header) error {
return err
}

// process the new block in order to update the snapshot
if err := i.processHeaders([]*types.Header{header}); err != nil {
return err
}

return nil
}

// ProcessHeaders updates the snapshot based on previously verified headers
func (i *Ibft) ProcessHeaders(headers []*types.Header) error {
return i.processHeaders(headers)
}

Kourin1996 marked this conversation as resolved.
Show resolved Hide resolved
// GetBlockCreator retrieves the block signer from the extra data field
func (i *Ibft) GetBlockCreator(header *types.Header) (types.Address, error) {
return ecrecoverFromHeader(header)
Expand Down