Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(state): improve node startup by optimizing availability score calculation #1338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading