From 493b979b95ffefb4618122b7919e369fd44a2ff0 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 19 Oct 2022 18:43:23 +0300 Subject: [PATCH] dbft: rev up, fix context timestamp initialization See nspcc-dev/dbft#64, fixes #2753. --- go.mod | 2 +- go.sum | 4 ++-- pkg/consensus/consensus.go | 6 ++++-- pkg/consensus/consensus_test.go | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 2a0bd53a4..308c6a647 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/holiman/uint256 v1.2.0 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mr-tron/base58 v1.2.0 - github.com/nspcc-dev/dbft v0.0.0-20221018080254-c7e1bf49ccd7 + github.com/nspcc-dev/dbft v0.0.0-20221020093431-31c1bbdc74f2 github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20220927123257-24c107e3a262 github.com/nspcc-dev/neofs-sdk-go v0.0.0-20220113123743-7f3162110659 diff --git a/go.sum b/go.sum index 4acbe2ce0..c20e8a758 100644 --- a/go.sum +++ b/go.sum @@ -251,8 +251,8 @@ github.com/nspcc-dev/dbft v0.0.0-20191209120240-0d6b7568d9ae/go.mod h1:3FjXOoHmA github.com/nspcc-dev/dbft v0.0.0-20200117124306-478e5cfbf03a/go.mod h1:/YFK+XOxxg0Bfm6P92lY5eDSLYfp06XOdL8KAVgXjVk= github.com/nspcc-dev/dbft v0.0.0-20200219114139-199d286ed6c1/go.mod h1:O0qtn62prQSqizzoagHmuuKoz8QMkU3SzBoKdEvm3aQ= github.com/nspcc-dev/dbft v0.0.0-20210721160347-1b03241391ac/go.mod h1:U8MSnEShH+o5hexfWJdze6uMFJteP0ko7J2frO7Yu1Y= -github.com/nspcc-dev/dbft v0.0.0-20221018080254-c7e1bf49ccd7 h1:RxVI9RFiHmpUvbuYIM5siLMiOvVt8P651BdmTstGi3Q= -github.com/nspcc-dev/dbft v0.0.0-20221018080254-c7e1bf49ccd7/go.mod h1:g9xisXmX9NP9MjioaTe862n9SlZTrP+6PVUWLBYOr98= +github.com/nspcc-dev/dbft v0.0.0-20221020093431-31c1bbdc74f2 h1:2soBy8en5W4/1Gvbog8RyVpEbarGWZwPxppZjffWzZE= +github.com/nspcc-dev/dbft v0.0.0-20221020093431-31c1bbdc74f2/go.mod h1:g9xisXmX9NP9MjioaTe862n9SlZTrP+6PVUWLBYOr98= github.com/nspcc-dev/go-ordered-json v0.0.0-20210915112629-e1b6cce73d02/go.mod h1:79bEUDEviBHJMFV6Iq6in57FEOCMcRhfQnfaf0ETA5U= github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22 h1:n4ZaFCKt1pQJd7PXoMJabZWK9ejjbLOVrkl/lOUmshg= github.com/nspcc-dev/go-ordered-json v0.0.0-20220111165707-25110be27d22/go.mod h1:79bEUDEviBHJMFV6Iq6in57FEOCMcRhfQnfaf0ETA5U= diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index f0db86045..03978792a 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -268,7 +268,9 @@ func (s *service) Name() string { func (s *service) Start() { if s.started.CAS(false, true) { s.log.Info("starting consensus service") - s.dbft.Start() + b, _ := s.Chain.GetBlock(s.Chain.CurrentBlockHash()) // Can't fail, we have some current block! + s.lastTimestamp = b.Timestamp + s.dbft.Start(s.lastTimestamp * nsInMs) s.Chain.SubscribeForBlocks(s.blockEvents) go s.eventLoop() } @@ -359,7 +361,7 @@ func (s *service) handleChainBlock(b *coreb.Block) { zap.Uint32("dbft index", s.dbft.BlockIndex), zap.Uint32("chain index", s.Chain.BlockHeight())) s.postBlock(b) - s.dbft.InitializeConsensus(0) + s.dbft.InitializeConsensus(0, b.Timestamp*nsInMs) } } diff --git a/pkg/consensus/consensus_test.go b/pkg/consensus/consensus_test.go index 904fe1693..fcca5b2f5 100644 --- a/pkg/consensus/consensus_test.go +++ b/pkg/consensus/consensus_test.go @@ -71,7 +71,7 @@ func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint3 require.NoError(t, bc.PoolTx(tx)) srv := newTestServiceWithChain(t, bc) - srv.dbft.Start() + srv.dbft.Start(0) // Register new candidate. b.Reset() @@ -164,7 +164,7 @@ func TestService_NextConsensus(t *testing.T) { func TestService_GetVerified(t *testing.T) { srv := newTestService(t) - srv.dbft.Start() + srv.dbft.Start(0) var txs []*transaction.Transaction for i := 0; i < 4; i++ { tx := transaction.New([]byte{byte(opcode.PUSH1)}, 100000) @@ -294,7 +294,7 @@ func TestService_getTx(t *testing.T) { func TestService_PrepareRequest(t *testing.T) { srv := newTestServiceWithState(t, true) - srv.dbft.Start() + srv.dbft.Start(0) t.Cleanup(srv.dbft.Timer.Stop) priv, _ := getTestValidator(1)