Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check: extend ProcessBlock callback with error handler #134

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
13 changes: 10 additions & 3 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@
return
}

d.lastBlockIndex = d.BlockIndex
d.lastBlockTime = d.Timer.Now()
d.block = d.CreateBlock()
hash := d.block.Hash()

Expand All @@ -124,8 +122,17 @@
zap.Stringer("merkle", d.block.MerkleRoot()),
zap.Stringer("prev", d.block.PrevHash()))

err := d.ProcessBlock(d.block)
if err != nil && d.isAntiMEVExtensionEnabled() { // errors not supported for AntiMEVExtensions mode off.
d.Logger.Info("can't process Block, waiting for more Commits to be collected",
zap.Error(err),
zap.Int("count", count))
return
}

Check warning on line 131 in check.go

View check run for this annotation

Codecov / codecov/patch

check.go#L127-L131

Added lines #L127 - L131 were not covered by tests

d.lastBlockIndex = d.BlockIndex
d.lastBlockTime = d.Timer.Now()
d.blockProcessed = true
d.ProcessBlock(d.block)

// Do not initialize consensus process immediately. It's the caller's duty to
// start the new block acceptance process and call Reset at the
Expand Down
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// ProcessBlock is called every time new preBlock is accepted.
ProcessPreBlock func(b PreBlock[H]) error
// ProcessBlock is called every time new block is accepted.
ProcessBlock func(b Block[H])
ProcessBlock func(b Block[H]) error
// GetBlock should return block with hash.
GetBlock func(h H) Block[H]
// WatchOnly tells if a node should only watch.
Expand Down Expand Up @@ -108,7 +108,7 @@
GetVerified: func() []Transaction[H] { return make([]Transaction[H], 0) },
VerifyBlock: func(Block[H]) bool { return true },
Broadcast: func(ConsensusPayload[H]) {},
ProcessBlock: func(Block[H]) {},
ProcessBlock: func(Block[H]) error { return nil },

Check warning on line 111 in config.go

View check run for this annotation

Codecov / codecov/patch

config.go#L111

Added line #L111 was not covered by tests
GetBlock: func(H) Block[H] { return nil },
WatchOnly: func() bool { return false },
CurrentHeight: nil,
Expand Down Expand Up @@ -276,7 +276,7 @@
}

// WithProcessBlock sets ProcessBlock.
func WithProcessBlock[H Hash](f func(b Block[H])) func(config *Config[H]) {
func WithProcessBlock[H Hash](f func(b Block[H]) error) func(config *Config[H]) {
return func(cfg *Config[H]) {
cfg.ProcessBlock = f
}
Expand Down
2 changes: 1 addition & 1 deletion dbft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ func (s *testState) getOptions() []func(*dbft.Config[crypto.Uint256]) {
}),
dbft.WithBroadcast[crypto.Uint256](func(p Payload) { s.ch = append(s.ch, p) }),
dbft.WithGetTx[crypto.Uint256](s.pool.Get),
dbft.WithProcessBlock[crypto.Uint256](func(b dbft.Block[crypto.Uint256]) { s.blocks = append(s.blocks, b) }),
dbft.WithProcessBlock[crypto.Uint256](func(b dbft.Block[crypto.Uint256]) error { s.blocks = append(s.blocks, b); return nil }),
dbft.WithWatchOnly[crypto.Uint256](func() bool { return false }),
dbft.WithGetBlock[crypto.Uint256](func(crypto.Uint256) dbft.Block[crypto.Uint256] { return nil }),
dbft.WithTimer[crypto.Uint256](timer.New()),
Expand Down
2 changes: 1 addition & 1 deletion internal/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func New(logger *zap.Logger, key dbft.PrivateKey, pub dbft.PublicKey,
getTx func(uint256 crypto.Uint256) dbft.Transaction[crypto.Uint256],
getVerified func() []dbft.Transaction[crypto.Uint256],
broadcast func(dbft.ConsensusPayload[crypto.Uint256]),
processBlock func(dbft.Block[crypto.Uint256]),
processBlock func(dbft.Block[crypto.Uint256]) error,
currentHeight func() uint32,
currentBlockHash func() crypto.Uint256,
getValidators func(...dbft.Transaction[crypto.Uint256]) []dbft.PublicKey,
Expand Down
3 changes: 2 additions & 1 deletion internal/simulation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
return n.validators
}

func (n *simNode) ProcessBlock(b dbft.Block[crypto.Uint256]) {
func (n *simNode) ProcessBlock(b dbft.Block[crypto.Uint256]) error {

Check warning on line 182 in internal/simulation/main.go

View check run for this annotation

Codecov / codecov/patch

internal/simulation/main.go#L182

Added line #L182 was not covered by tests
n.d.Logger.Debug("received block", zap.Uint32("height", b.Index()))

for _, tx := range b.Transactions() {
Expand All @@ -188,6 +188,7 @@

n.height = b.Index()
n.lastHash = b.Hash()
return nil

Check warning on line 191 in internal/simulation/main.go

View check run for this annotation

Codecov / codecov/patch

internal/simulation/main.go#L191

Added line #L191 was not covered by tests
}

// VerifyPayload verifies that payload was received from a good validator.
Expand Down
Loading