From 82b3f0cedaf76290a123f419bf6fef6aed742592 Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Sun, 23 Jul 2023 12:41:04 -0400 Subject: [PATCH] Updated. --- consensus/consensus.go | 4 ++-- consensus/consensus_test.go | 8 ++++---- consensus/consensus_v2.go | 5 +++-- consensus/validator.go | 2 +- consensus/view_change_msg.go | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/consensus/consensus.go b/consensus/consensus.go index bdb4803bb..1e35773ef 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -268,7 +268,7 @@ func New( consensus := Consensus{ mutex: &sync.RWMutex{}, ShardID: shard, - fBFTLog: NewFBFTLog(), + fBFTLog: NewFBFTLog(VerifyNewBlock(registry.GetWebHooks(), registry.GetBlockchain(), registry.GetBeaconchain())), phase: FBFTAnnounce, current: State{mode: Normal}, Decider: Decider, @@ -302,7 +302,7 @@ func New( consensus.RndChannel = make(chan [vdfAndSeedSize]byte) consensus.IgnoreViewIDCheck = abool.NewBool(false) // Make Sure Verifier is not null - consensus.vc = newViewChange(consensus.FBFTLog.BlockVerify) + consensus.vc = newViewChange(consensus.fBFTLog.BlockVerify) // init prometheus metrics initMetrics() consensus.AddPubkeyMetrics() diff --git a/consensus/consensus_test.go b/consensus/consensus_test.go index 83d2021e3..725e70c3f 100644 --- a/consensus/consensus_test.go +++ b/consensus/consensus_test.go @@ -22,7 +22,7 @@ func TestConsensusInitialization(t *testing.T) { assert.NoError(t, err) messageSender := &MessageSender{host: host, retryTimes: int(phaseDuration.Seconds()) / RetryIntervalInSec} - fbtLog := NewFBFTLog(consensus.FBFTLog.verifyNewBlock) + fbtLog := NewFBFTLog(nil) state := State{mode: Normal} timeouts := createTimeout() @@ -37,10 +37,10 @@ func TestConsensusInitialization(t *testing.T) { assert.IsType(t, make(chan struct{}), consensus.BlockNumLowChan) // FBFTLog - assert.Equal(t, fbtLog.blocks, consensus.FBFTLog.blocks) - assert.Equal(t, fbtLog.messages, consensus.FBFTLog.messages) + assert.Equal(t, fbtLog.blocks, consensus.fBFTLog.blocks) + assert.Equal(t, fbtLog.messages, consensus.fBFTLog.messages) assert.Equal(t, len(fbtLog.verifiedBlocks), 0) - assert.Equal(t, fbtLog.verifiedBlocks, consensus.FBFTLog.verifiedBlocks) + assert.Equal(t, fbtLog.verifiedBlocks, consensus.fBFTLog.verifiedBlocks) assert.NotNil(t, consensus.FBFTLog()) assert.Equal(t, FBFTAnnounce, consensus.phase) diff --git a/consensus/consensus_v2.go b/consensus/consensus_v2.go index 27c9b15bf..258d82a8f 100644 --- a/consensus/consensus_v2.go +++ b/consensus/consensus_v2.go @@ -4,11 +4,12 @@ import ( "bytes" "context" "encoding/hex" - libp2p_peer "github.com/libp2p/go-libp2p/core/peer" "math/big" "sync/atomic" "time" + libp2p_peer "github.com/libp2p/go-libp2p/core/peer" + "github.com/ethereum/go-ethereum/common" bls2 "github.com/harmony-one/bls/ffi/go/bls" "github.com/harmony-one/harmony/consensus/signature" @@ -631,7 +632,7 @@ func (consensus *Consensus) tryCatchup() error { } blk.SetCurrentCommitSig(msg.Payload) - if err := consensus.FBFTLog.verifyBlock(blk); err != nil { + if err := consensus.fBFTLog.verifyBlock(blk); err != nil { consensus.getLogger().Err(err).Msg("[TryCatchup] failed block verifier") return err } diff --git a/consensus/validator.go b/consensus/validator.go index 02f92cd50..6a1f21e1a 100644 --- a/consensus/validator.go +++ b/consensus/validator.go @@ -131,7 +131,7 @@ func (consensus *Consensus) validateNewBlock(recvMsg *FBFTMessage) (*types.Block Hex("blockHash", recvMsg.BlockHash[:]). Msg("[validateNewBlock] Prepared message and block added") - if err := consensus.FBFTLog.verifyBlock(&blockObj); err != nil { + if err := consensus.fBFTLog.verifyBlock(&blockObj); err != nil { consensus.getLogger().Error().Err(err).Msg("[validateNewBlock] Block verification failed") return nil, errors.Errorf("Block verification failed: %s", err.Error()) } diff --git a/consensus/view_change_msg.go b/consensus/view_change_msg.go index 21ec801aa..c0a9863dd 100644 --- a/consensus/view_change_msg.go +++ b/consensus/view_change_msg.go @@ -45,7 +45,7 @@ func (consensus *Consensus) constructViewChangeMessage(priKey *bls.PrivateKeyWra Interface("preparedMsg", preparedMsg). Msg("[constructViewChangeMessage] found prepared msg") if block != nil { - if err := consensus.FBFTLog.verifyBlock(block); err == nil { + if err := consensus.fBFTLog.verifyBlock(block); err == nil { tmpEncoded, err := rlp.EncodeToBytes(block) if err != nil { consensus.getLogger().Err(err).Msg("[constructViewChangeMessage] Failed encoding block")