Skip to content

Commit

Permalink
consensus: remove unnecessary call to ComputeNextBlockValidators
Browse files Browse the repository at this point in the history
dBFT doesn't use validators got from this call to GetValidators callback,
because NeoGo doesn't properly set WithGetConsensusAddress, and thus
this call can be safely skipped. Instead, NeoGo fills NextConsensus field
by itself in NewBlockFromContext callback.

This commit technically doesn't perform any functional changes and doesn't
affect the problem described in #3253 in any way. This commit is just a
removal of the code that was never used by NeoGo library.

This commit is a direct consequence of nspcc-dev/dbft#84.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Dec 21, 2023
1 parent d7d850a commit df818d3
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,9 @@ func (s *service) getValidators(txes ...block.Transaction) []crypto.PublicKey {
pKeys, err = s.Chain.GetNextBlockValidators()
} else {

Check warning on line 684 in pkg/consensus/consensus.go

View workflow job for this annotation

GitHub Actions / Lint

empty-block: this block is empty, you can remove it (revive)
// getValidators with non-empty args is used by dbft to fill block's
// NextConsensus field, ComputeNextBlockValidators will return proper
// value for NextConsensus wrt dBFT epoch start/end.
pKeys = s.Chain.ComputeNextBlockValidators()
// NextConsensus field, but NeoGo doesn't provide WithGetConsensusAddress
// callback and fills NextConsensus by itself via WithNewBlockFromContext
// callback. Thus, leave pKeys empty here.
}
if err != nil {
s.log.Error("error while trying to get validators", zap.Error(err))
Expand Down Expand Up @@ -727,6 +727,16 @@ func (s *service) newBlockFromContext(ctx *dbft.Context) block.Block {
block.PrevStateRoot = sr.Root
}

// ComputeNextBlockValidators returns proper set of validators wrt dBFT epochs
// boundary. I.e. for the last block in the dBFT epoch this method returns the
// list of validators recalculated from the latest relevant information about
// NEO votes; in this case list of validators may differ from the one returned
// by GetNextBlockValidators. For the not-last block of dBFT epoch this method
// returns the same list as GetNextBlockValidators. Note, that by this moment
// we must be sure that previous block was successfully persisted to chain
// (i.e. PostPersist was completed for native Neo contract and PostPersist
// execution cache was persisted to s.Chain's DAO), otherwise the wrong
// (outdated, relevant for the previous dBFT epoch) value will be returned.
var validators = s.Chain.ComputeNextBlockValidators()
script, err := smartcontract.CreateDefaultMultiSigRedeemScript(validators)
if err != nil {
Expand Down

0 comments on commit df818d3

Please sign in to comment.