mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-22 19:29:39 +00:00
consensus: check transactions count during PrepareRequest verification
This commit is contained in:
parent
23a3514cc0
commit
38103dcc7a
2 changed files with 14 additions and 3 deletions
|
@ -466,9 +466,10 @@ func (s *service) verifyBlock(b block.Block) bool {
|
|||
}
|
||||
|
||||
var (
|
||||
errInvalidPrevHash = errors.New("invalid PrevHash")
|
||||
errInvalidVersion = errors.New("invalid Version")
|
||||
errInvalidStateRoot = errors.New("state root mismatch")
|
||||
errInvalidPrevHash = errors.New("invalid PrevHash")
|
||||
errInvalidVersion = errors.New("invalid Version")
|
||||
errInvalidStateRoot = errors.New("state root mismatch")
|
||||
errInvalidTransactionsCount = errors.New("invalid transactions count")
|
||||
)
|
||||
|
||||
func (s *service) verifyRequest(p payload.ConsensusPayload) error {
|
||||
|
@ -487,6 +488,9 @@ func (s *service) verifyRequest(p payload.ConsensusPayload) error {
|
|||
return fmt.Errorf("%w: %s != %s", errInvalidStateRoot, sr.Root, req.stateRoot)
|
||||
}
|
||||
}
|
||||
if len(req.TransactionHashes()) > int(s.ProtocolConfiguration.MaxTransactionsPerBlock) {
|
||||
return fmt.Errorf("%w: max = %d, got %d", errInvalidTransactionsCount, s.ProtocolConfiguration.MaxTransactionsPerBlock, len(req.TransactionHashes()))
|
||||
}
|
||||
// Save lastProposal for getVerified().
|
||||
s.lastProposal = req.transactionHashes
|
||||
|
||||
|
|
|
@ -323,6 +323,13 @@ func TestService_PrepareRequest(t *testing.T) {
|
|||
|
||||
sr, err := srv.Chain.GetStateModule().GetStateRoot(srv.dbft.BlockIndex - 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
checkRequest(t, errInvalidTransactionsCount, &prepareRequest{stateRootEnabled: true,
|
||||
prevHash: prevHash,
|
||||
stateRoot: sr.Root,
|
||||
transactionHashes: make([]util.Uint256, srv.ProtocolConfiguration.MaxTransactionsPerBlock+1),
|
||||
})
|
||||
|
||||
checkRequest(t, nil, &prepareRequest{
|
||||
stateRootEnabled: true,
|
||||
prevHash: prevHash,
|
||||
|
|
Loading…
Reference in a new issue