Skip to content

Commit

Permalink
fix(state): improve node startup by optimizing availability score cal…
Browse files Browse the repository at this point in the history
…culation (#1338)
  • Loading branch information
Ja7ad authored Jun 11, 2024
1 parent 3c0cf1d commit 857d444
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion consensus/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion fastconsensus/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 7 additions & 2 deletions state/state.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package state

import (
"bytes"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 857d444

Please sign in to comment.