consensus: fix nonce handling
It was broken somewhere between2f490a3403
and85ce207f40
leading to panic on watch only node: 2021-07-21T16:21:39.201+0200 INFO received Commit {"validator": 3} panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0xbcc59e] goroutine 486 [running]: github.com/nspcc-dev/neo-go/pkg/consensus.(*service).newBlockFromContext(0xc0001629a0, 0xc000308000, 0xc0010fa000, 0x2cb417800) github.com/nspcc-dev/neo-go/pkg/consensus/consensus.go:664 +0xbe github.com/nspcc-dev/dbft.(*Context).MakeHeader(...) github.com/nspcc-dev/dbft@v0.0.0-20210302103605-cc75991b7cfb/context.go:270 github.com/nspcc-dev/dbft.(*DBFT).onCommit(0xc000308000, 0x138c998, 0xc000115110) github.com/nspcc-dev/dbft@v0.0.0-20210302103605-cc75991b7cfb/dbft.go:487 +0x575 github.com/nspcc-dev/dbft.(*DBFT).OnReceive(0xc000308000, 0x138c998, 0xc000115110) github.com/nspcc-dev/dbft@v0.0.0-20210302103605-cc75991b7cfb/dbft.go:251 +0xef5 github.com/nspcc-dev/neo-go/pkg/consensus.(*service).eventLoop(0xc0001629a0) github.com/nspcc-dev/neo-go/pkg/consensus/consensus.go:312 +0x7d6 created by github.com/nspcc-dev/neo-go/pkg/consensus.(*service).Start github.com/nspcc-dev/neo-go/pkg/consensus/consensus.go:262 +0xdc In fact, nonce is correctly provided by dbft library (since Legacy), we just need to use it here.
This commit is contained in:
parent
7d6898677b
commit
4d2ecab16f
4 changed files with 5 additions and 16 deletions
|
@ -1,8 +1,6 @@
|
|||
package consensus
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
@ -241,19 +239,9 @@ func (s *service) newPrepareRequest() payload.PrepareRequest {
|
|||
panic(err)
|
||||
}
|
||||
}
|
||||
r.nonce = s.getNonce()
|
||||
return r
|
||||
}
|
||||
|
||||
func (s *service) getNonce() uint64 {
|
||||
b := make([]byte, 8)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return binary.LittleEndian.Uint64(b)
|
||||
}
|
||||
|
||||
func (s *service) Start() {
|
||||
if s.started.CAS(false, true) {
|
||||
s.log.Info("starting consensus service")
|
||||
|
@ -661,7 +649,7 @@ func (s *service) newBlockFromContext(ctx *dbft.Context) block.Block {
|
|||
block := &neoBlock{network: s.ProtocolConfiguration.Magic}
|
||||
|
||||
block.Block.Timestamp = ctx.Timestamp / nsInMs
|
||||
block.Block.Nonce = ctx.PreparationPayloads[ctx.PrimaryIndex].GetPrepareRequest().Nonce()
|
||||
block.Block.Nonce = ctx.Nonce
|
||||
block.Block.Index = ctx.BlockIndex
|
||||
if s.ProtocolConfiguration.StateRootInHeader {
|
||||
sr, err := s.Chain.GetStateModule().GetStateRoot(ctx.BlockIndex - 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue