From f0dc999e1bed55b1a08749b99303f0336164ed5e Mon Sep 17 00:00:00 2001 From: Konstantin <355847+Frozen@users.noreply.github.com> Date: Mon, 26 Feb 2024 15:02:04 -0400 Subject: [PATCH 1/3] Get only valid blocks. (#4628) --- consensus/fbft_log.go | 13 +++++++++++-- consensus/view_change_msg.go | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/consensus/fbft_log.go b/consensus/fbft_log.go index 982aecab7..34637183a 100644 --- a/consensus/fbft_log.go +++ b/consensus/fbft_log.go @@ -222,11 +222,20 @@ func (log *FBFTLog) GetMessagesByTypeSeqViewHash(typ msg_pb.MessageType, blockNu return found } +func (log *FBFTLog) all(filters []func(*FBFTMessage, *FBFTLog) bool, value *FBFTMessage) bool { + for _, filter := range filters { + if !filter(value, log) { + return false + } + } + return true +} + // GetMessagesByTypeSeq returns pbft messages with matching type, blockNum -func (log *FBFTLog) GetMessagesByTypeSeq(typ msg_pb.MessageType, blockNum uint64) []*FBFTMessage { +func (log *FBFTLog) GetMessagesByTypeSeq(typ msg_pb.MessageType, blockNum uint64, filters ...func(message *FBFTMessage, log *FBFTLog) bool) []*FBFTMessage { var found []*FBFTMessage for _, msg := range log.messages { - if msg.MessageType == typ && msg.BlockNum == blockNum && msg.Verified { + if msg.MessageType == typ && msg.BlockNum == blockNum && msg.Verified && log.all(filters, msg) { found = append(found, msg) } } diff --git a/consensus/view_change_msg.go b/consensus/view_change_msg.go index 6c4b08005..8272134c5 100644 --- a/consensus/view_change_msg.go +++ b/consensus/view_change_msg.go @@ -33,7 +33,9 @@ func (consensus *Consensus) constructViewChangeMessage(priKey *bls.PrivateKeyWra } preparedMsgs := consensus.fBFTLog.GetMessagesByTypeSeq( - msg_pb.MessageType_PREPARED, consensus.getBlockNum(), + msg_pb.MessageType_PREPARED, consensus.getBlockNum(), func(message *FBFTMessage, log *FBFTLog) bool { + return log.IsBlockVerified(message.BlockHash) + }, ) preparedMsg := consensus.fBFTLog.FindMessageByMaxViewID(preparedMsgs) From 2dee6c6b2e9375f3da01c1ee7fbcde02ab58eae2 Mon Sep 17 00:00:00 2001 From: Konstantin <355847+Frozen@users.noreply.github.com> Date: Mon, 26 Feb 2024 17:16:23 -0400 Subject: [PATCH 2/3] Revert "Get only valid blocks. (#4628)" (#4637) This reverts commit f0dc999e1bed55b1a08749b99303f0336164ed5e. --- consensus/fbft_log.go | 13 ++----------- consensus/view_change_msg.go | 4 +--- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/consensus/fbft_log.go b/consensus/fbft_log.go index 34637183a..982aecab7 100644 --- a/consensus/fbft_log.go +++ b/consensus/fbft_log.go @@ -222,20 +222,11 @@ func (log *FBFTLog) GetMessagesByTypeSeqViewHash(typ msg_pb.MessageType, blockNu return found } -func (log *FBFTLog) all(filters []func(*FBFTMessage, *FBFTLog) bool, value *FBFTMessage) bool { - for _, filter := range filters { - if !filter(value, log) { - return false - } - } - return true -} - // GetMessagesByTypeSeq returns pbft messages with matching type, blockNum -func (log *FBFTLog) GetMessagesByTypeSeq(typ msg_pb.MessageType, blockNum uint64, filters ...func(message *FBFTMessage, log *FBFTLog) bool) []*FBFTMessage { +func (log *FBFTLog) GetMessagesByTypeSeq(typ msg_pb.MessageType, blockNum uint64) []*FBFTMessage { var found []*FBFTMessage for _, msg := range log.messages { - if msg.MessageType == typ && msg.BlockNum == blockNum && msg.Verified && log.all(filters, msg) { + if msg.MessageType == typ && msg.BlockNum == blockNum && msg.Verified { found = append(found, msg) } } diff --git a/consensus/view_change_msg.go b/consensus/view_change_msg.go index 8272134c5..6c4b08005 100644 --- a/consensus/view_change_msg.go +++ b/consensus/view_change_msg.go @@ -33,9 +33,7 @@ func (consensus *Consensus) constructViewChangeMessage(priKey *bls.PrivateKeyWra } preparedMsgs := consensus.fBFTLog.GetMessagesByTypeSeq( - msg_pb.MessageType_PREPARED, consensus.getBlockNum(), func(message *FBFTMessage, log *FBFTLog) bool { - return log.IsBlockVerified(message.BlockHash) - }, + msg_pb.MessageType_PREPARED, consensus.getBlockNum(), ) preparedMsg := consensus.fBFTLog.FindMessageByMaxViewID(preparedMsgs) From c32319c37788134325d2914ab18d60e76bff728c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CGheisMohammadi=E2=80=9D?= <36589218+GheisMohammadi@users.noreply.github.com> Date: Mon, 11 Mar 2024 08:23:33 +0100 Subject: [PATCH 3/3] set SnapshotLimit to zero by default for all networks --- cmd/harmony/config.go | 8 +++++++- cmd/harmony/flags_test.go | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/harmony/config.go b/cmd/harmony/config.go index 037221835..0b798551a 100644 --- a/cmd/harmony/config.go +++ b/cmd/harmony/config.go @@ -161,9 +161,15 @@ func getDefaultCacheConfig(nt nodeconfig.NetworkType) harmonyconfig.CacheConfig case nodeconfig.Mainnet: cacheConfig.Disabled = true cacheConfig.Preimages = true + cacheConfig.SnapshotLimit = 0 case nodeconfig.Testnet: - cacheConfig.Disabled = false + cacheConfig.Disabled = true + cacheConfig.Preimages = true + cacheConfig.SnapshotLimit = 0 + case nodeconfig.Partner: + cacheConfig.Disabled = true cacheConfig.Preimages = true + cacheConfig.SnapshotLimit = 0 case nodeconfig.Localnet: cacheConfig.Disabled = false cacheConfig.Preimages = false diff --git a/cmd/harmony/flags_test.go b/cmd/harmony/flags_test.go index ffe261b39..50ed02fa2 100644 --- a/cmd/harmony/flags_test.go +++ b/cmd/harmony/flags_test.go @@ -1440,7 +1440,7 @@ func TestCacheFlags(t *testing.T) { TrieNodeLimit: defaultCacheConfig.TrieNodeLimit, TriesInMemory: defaultCacheConfig.TriesInMemory, TrieTimeLimit: defaultCacheConfig.TrieTimeLimit, - SnapshotLimit: defaultCacheConfig.SnapshotLimit, + SnapshotLimit: 0, // based on network type, SnapshotWait: defaultCacheConfig.SnapshotWait, Preimages: defaultCacheConfig.Preimages, // based on network type SnapshotNoBuild: defaultCacheConfig.SnapshotNoBuild,