From 857d444bd09a84737ed9cffa219674c396ae02b8 Mon Sep 17 00:00:00 2001 From: Javad Rajabzadeh Date: Tue, 11 Jun 2024 14:14:39 +0330 Subject: [PATCH] fix(state): improve node startup by optimizing availability score calculation (#1338) --- consensus/propose.go | 2 +- fastconsensus/propose.go | 2 +- state/state.go | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/consensus/propose.go b/consensus/propose.go index e50939f10..4b9debfbf 100644 --- a/consensus/propose.go +++ b/consensus/propose.go @@ -29,7 +29,7 @@ func (s *proposeState) decide() { // TODO: write test for me score := s.bcState.AvailabilityScore(proposer.Number()) - // Based on PIP-19, if the Availability Score is less than 0.9, + // Based on PIP-19, if the Availability Score is less than the Minimum threshold, // we initiate the Change-Proposer phase. if score < s.config.MinimumAvailabilityScore { s.logger.Info("availability score of proposer is low", diff --git a/fastconsensus/propose.go b/fastconsensus/propose.go index 99dacabb2..1adaaaba5 100644 --- a/fastconsensus/propose.go +++ b/fastconsensus/propose.go @@ -29,7 +29,7 @@ func (s *proposeState) decide() { // TODO: write test for me score := s.bcState.AvailabilityScore(proposer.Number()) - // Based on PIP-19, if the Availability Score is less than 0.9, + // Based on PIP-19, if the Availability Score is less than the Minimum threshold, // we initiate the Change-Proposer phase. if score < s.config.MinimumAvailabilityScore { s.logger.Info("availability score of proposer is low", diff --git a/state/state.go b/state/state.go index 0d8cceb7a..e5f2ecbe0 100644 --- a/state/state.go +++ b/state/state.go @@ -1,6 +1,7 @@ package state import ( + "bytes" "fmt" "sync" "time" @@ -110,11 +111,15 @@ func LoadOrNewState( if err != nil { return nil, err } - blk, err := cb.ToBlock() + // This code decodes the block certificate from the block data + // without decoding the header and transactions. + r := bytes.NewReader(cb.Data[138:]) // Block header is 138 bytes + cert := new(certificate.BlockCertificate) + err = cert.Decode(r) if err != nil { return nil, err } - scoreMgr.SetCertificate(blk.PrevCertificate()) + scoreMgr.SetCertificate(cert) } st.scoreMgr = scoreMgr