-
Notifications
You must be signed in to change notification settings - Fork 71
Committed generators balances legacy state hash #1978
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
Changes from all commits
187d6cb
5f59abe
e8be16c
185cff1
a2588e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package state | |
| import ( | ||
| "bytes" | ||
| "context" | ||
| "encoding/binary" | ||
| stderrs "errors" | ||
| "fmt" | ||
| "io" | ||
|
|
@@ -74,6 +75,7 @@ type blockchainEntitiesStorage struct { | |
| patches *patchesStorage | ||
| commitments *commitments | ||
| finalizations *finalizations | ||
| settings *settings.BlockchainSettings | ||
| calculateHashes bool | ||
| } | ||
|
|
||
|
|
@@ -110,14 +112,48 @@ func newBlockchainEntitiesStorage(hs *historyStorage, sets *settings.BlockchainS | |
| newPatchesStorage(hs, sets.AddressSchemeCharacter), | ||
| newCommitments(hs, calcHashes), | ||
| newFinalizations(hs), | ||
| sets, | ||
| calcHashes, | ||
| }, nil | ||
| } | ||
|
|
||
| func calculateCommittedGeneratorsBalancesStateHash( | ||
| s *blockchainEntitiesStorage, finalityActivated bool, blockHeight proto.Height, | ||
| ) (crypto.Digest, error) { | ||
| generatorsBalancesSH := s.commitments.hasher.emptyHash // take empty hash from commitments record | ||
| if !finalityActivated { | ||
| return generatorsBalancesSH, nil // not activated, return empty hash | ||
| } | ||
| finalityActivationHeight, err := s.features.newestActivationHeight(int16(settings.DeterministicFinality)) | ||
| if err != nil { | ||
| return crypto.Digest{}, fmt.Errorf("failed to get finality activation height: %w", err) | ||
| } | ||
| period, err := CurrentGenerationPeriodStart(finalityActivationHeight, blockHeight, s.settings.GenerationPeriod) | ||
| if err != nil { | ||
| return crypto.Digest{}, fmt.Errorf("failed to get current generation period start: %w", err) | ||
| } | ||
| // generators are sorted by their commitment index, so the balances will be in the same order. | ||
| generators, err := s.commitments.CommittedGeneratorsAddresses(period, s.settings.AddressSchemeCharacter) | ||
| if err != nil { | ||
| return crypto.Digest{}, fmt.Errorf("failed to get committed generators addresses: %w", err) | ||
| } | ||
| generatorsBalancesRecord := make([]byte, 0, len(generators)*uint64Size) | ||
| for _, addr := range generators { | ||
| bal, bErr := s.balances.newestGeneratingBalance(addr.ID(), blockHeight) | ||
| if bErr != nil { | ||
| return crypto.Digest{}, fmt.Errorf("failed to get generating balance for address %s: %w", | ||
| addr.String(), bErr, | ||
| ) | ||
| } | ||
| generatorsBalancesRecord = binary.BigEndian.AppendUint64(generatorsBalancesRecord, bal) | ||
| } | ||
| return crypto.FastHash(generatorsBalancesRecord) | ||
|
Comment on lines
+136
to
+150
|
||
| } | ||
|
|
||
| func (s *blockchainEntitiesStorage) putStateHash( | ||
| prevHash []byte, height uint64, blockID proto.BlockID, | ||
| ) (proto.StateHash, error) { | ||
| finalityActivated := s.features.isActivatedAtHeight(int16(settings.DeterministicFinality), height) | ||
| finalityActivated := s.features.newestIsActivatedAtHeight(int16(settings.DeterministicFinality), height) | ||
| fhV1 := proto.FieldsHashesV1{ | ||
| WavesBalanceHash: s.balances.wavesHashAt(blockID), | ||
| AssetBalanceHash: s.balances.assetsHashAt(blockID), | ||
|
|
@@ -129,7 +165,19 @@ func (s *blockchainEntitiesStorage) putStateHash( | |
| SponsorshipHash: s.sponsoredAssets.hasher.stateHashAt(blockID), | ||
| AliasesHash: s.aliases.hasher.stateHashAt(blockID), | ||
| } | ||
| sh := proto.NewLegacyStateHash(finalityActivated, blockID, fhV1, s.commitments.hasher.stateHashAt(blockID)) | ||
| generatorsBalancesSH, err := calculateCommittedGeneratorsBalancesStateHash(s, finalityActivated, height) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| sh, shErr := proto.NewLegacyStateHash(blockID, fhV1, | ||
| proto.LegacyStateHashFeatureActivated{ | ||
| FinalityActivated: finalityActivated, | ||
| }, | ||
| proto.LegacyStateHashV2Opt(s.commitments.hasher.stateHashAt(blockID), generatorsBalancesSH), | ||
| ) | ||
| if shErr != nil { | ||
| return nil, shErr | ||
| } | ||
| if gErr := sh.GenerateSumHash(prevHash); gErr != nil { | ||
| return nil, gErr | ||
| } | ||
|
|
@@ -158,7 +206,7 @@ func (s *blockchainEntitiesStorage) prepareHashes() error { | |
| if err := s.aliases.prepareHashes(); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| return s.commitments.prepareHashes() | ||
| } | ||
|
|
||
| func (s *blockchainEntitiesStorage) handleLegacyStateHashes(blockchainHeight uint64, blockIds []proto.BlockID) error { | ||
|
|
@@ -224,6 +272,7 @@ func (s *blockchainEntitiesStorage) reset() { | |
| s.leases.reset() | ||
| s.sponsoredAssets.reset() | ||
| s.aliases.reset() | ||
| s.commitments.reset() | ||
| } | ||
|
|
||
| func (s *blockchainEntitiesStorage) flush() error { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.