-
Notifications
You must be signed in to change notification settings - Fork 71
Burn deposit #2070
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
base: determenistic-finality-feature
Are you sure you want to change the base?
Burn deposit #2070
Changes from 18 commits
38b9a0d
5898f71
9982d9f
4d4bd2d
9c31ae1
87e51e6
16778ec
7245f18
90b617b
8a23896
4af54c0
109c7d3
6f125ff
c830be1
19153b2
f3b0bca
446a034
8a51c43
aacf0f8
443cd7e
c512489
cae8e1f
eed3b3b
f6eb621
5b022be
3169f46
d025cfb
a7ab7ea
bd48325
6aa3c0a
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 |
|---|---|---|
|
|
@@ -258,16 +258,29 @@ func (a *NGState) endorseParentWithEachKey( | |
| block *proto.Block, | ||
| blockHeight proto.Height, | ||
| ) error { | ||
| activationHeight, err := a.baseInfo.storage.ActivationHeight(int16(settings.DeterministicFinality)) | ||
| if err != nil { | ||
| return a.Errorf(errors.Wrapf(err, "failed to get activation height for finality %s", block.BlockID())) | ||
| // Check current generators set. | ||
| gs, err := a.baseInfo.storage.CommittedGenerators(blockHeight) | ||
| if err != nil && !errors.Is(err, state.ErrNoGeneratorsSet) { | ||
| return a.Errorf(errors.Wrapf(err, "failed to get generators for block '%s'", block.BlockID())) | ||
| } | ||
|
|
||
| periodStart, err := state.CurrentGenerationPeriodStart(activationHeight, blockHeight, a.baseInfo.generationPeriod) | ||
| if err != nil { | ||
| return a.Errorf(errors.Wrapf(err, "failed to get current generation period, block %s", block.BlockID())) | ||
| if errors.Is(err, state.ErrNoGeneratorsSet) || len(gs) == 0 { | ||
| slog.Debug("Generator set is empty, skipping block endorsement", slog.Uint64("height", blockHeight)) | ||
| return nil | ||
| } | ||
|
|
||
| // Following variables are used for logging only. | ||
| var activationHeight proto.Height | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This variable declaration can be moved inside
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
| var periodStart uint32 | ||
| if slog.Default().Enabled(context.Background(), slog.LevelDebug) { | ||
| activationHeight, err = a.baseInfo.storage.ActivationHeight(int16(settings.DeterministicFinality)) | ||
| if err != nil { | ||
| return a.Errorf(errors.Wrapf(err, "failed to get activation height for finality %s", block.BlockID())) | ||
| } | ||
| periodStart, err = state.CurrentGenerationPeriodStart(activationHeight, blockHeight, a.baseInfo.generationPeriod) | ||
| if err != nil { | ||
| return a.Errorf(errors.Wrapf(err, "failed to get current generation period, block %s", block.BlockID())) | ||
| } | ||
| } | ||
| for i := range sks { | ||
| sk := sks[i] | ||
| pk, pkErr := sk.PublicKey() | ||
|
|
@@ -278,13 +291,13 @@ func (a *NGState) endorseParentWithEachKey( | |
| slog.Int("SeedIndex", i), slog.String("BLS PublicKey", pk.String()), | ||
| slog.Any("BlockID", block.BlockID()), slog.Any("GenerationPeriodStart", periodStart)) | ||
|
|
||
| g, gErr := a.baseInfo.storage.FindGenerator(state.ByBLSPublicKey(pk)) | ||
| g, gErr := a.baseInfo.storage.FindGenerator(blockHeight, state.ByBLSPublicKey(pk)) | ||
| if gErr != nil { | ||
| slog.Warn("Wallet's BLS public key is not in the generators set", | ||
| slog.String("BLS PublicKey", pk.String()), logging.Error(gErr)) | ||
| continue | ||
| } | ||
| if g.GenerationBalance() == 0 { | ||
| if g.Balance == 0 { | ||
| slog.Debug("Wallet's BLS public key has insufficient generation balance", | ||
| slog.Int("SeedIndex", i), slog.String("BLS PublicKey", pk.String()), | ||
| slog.Any("BlockID", block.BlockID()), slog.Any("GenerationPeriodStart", periodStart)) | ||
|
|
@@ -316,12 +329,15 @@ func (a *NGState) BlockEndorsement(blockEndorsement *proto.BlockEndorsement) (St | |
| } | ||
|
|
||
| top := a.baseInfo.storage.TopBlock() | ||
|
|
||
| h, err := a.baseInfo.storage.Height() | ||
| if err != nil { | ||
| return a, nil, a.Errorf(errors.Wrapf(err, "failed to retrieve current height")) | ||
| } | ||
| generatorIndex, err := safecast.Convert[uint32](blockEndorsement.EndorserIndex) | ||
| if err != nil { | ||
| return a, nil, a.Errorf(errors.Wrapf(err, "failed to convert endorser index to uint32")) | ||
| } | ||
| gi, err := a.baseInfo.storage.FindGenerator(state.ByIndex(generatorIndex)) | ||
| gi, err := a.baseInfo.storage.FindGenerator(h, state.ByIndex(generatorIndex)) | ||
| if err != nil { | ||
| return a, nil, a.Errorf(errors.Wrapf(err, "failed to find generator by index")) | ||
| } | ||
|
|
@@ -334,8 +350,8 @@ func (a *NGState) BlockEndorsement(blockEndorsement *proto.BlockEndorsement) (St | |
| return a, nil, a.Errorf(errors.Wrapf(err, "failed to get last finalized block header for endorser address")) | ||
| } | ||
| // TODO check if generator is in the generator set. | ||
| endorserPK := gi.BLSPublicKey() | ||
| balance := gi.GenerationBalance() | ||
| endorserPK := gi.BLSPublicKey | ||
| balance := gi.Balance | ||
| added, addErr := a.baseInfo.endorsements.Add(blockEndorsement, endorserPK, | ||
| localFinalizedHeight, localFinalizedBlockHeader.BlockID(), balance, top.Parent) | ||
| if addErr != nil { | ||
|
|
@@ -457,7 +473,7 @@ func (a *NGState) MinedBlock( | |
|
|
||
| func (a *NGState) Endorse(parentBlockID proto.BlockID, | ||
| endorser state.GeneratorInfo, endorserSK bls.SecretKey) error { | ||
| endorserIndex := endorser.Index() | ||
| endorserIndex := endorser.Index | ||
| lastFinalizedHeight, err := a.baseInfo.storage.LastFinalizedHeight() | ||
| if err != nil { | ||
| return a.Errorf(errors.Wrap(err, "failed to get last finalized block height")) | ||
|
|
@@ -514,10 +530,10 @@ func (a *NGState) addAndBroadcastOwnEndorsement( | |
| top := a.baseInfo.storage.TopBlock() | ||
| added, addErr := a.baseInfo.endorsements.Add( | ||
| parentBlockEndorsement, | ||
| endorser.BLSPublicKey(), | ||
| endorser.BLSPublicKey, | ||
| lastFinalizedHeight, | ||
| lastFinalizedBlockID, | ||
| endorser.GenerationBalance(), | ||
| endorser.Balance, | ||
| top.Parent, | ||
| ) | ||
| if addErr != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import ( | |
| "github.com/wavesplatform/gowaves/pkg/p2p/peer" | ||
| "github.com/wavesplatform/gowaves/pkg/p2p/peer/extension" | ||
| "github.com/wavesplatform/gowaves/pkg/proto" | ||
| "github.com/wavesplatform/gowaves/pkg/settings" | ||
| "github.com/wavesplatform/gowaves/pkg/state" | ||
| "github.com/wavesplatform/gowaves/pkg/types" | ||
| ) | ||
|
|
@@ -200,22 +201,26 @@ func (a *SyncState) BlockSnapshot( | |
| func (a *SyncState) MinedBlock( | ||
| block *proto.Block, limits proto.MiningLimits, keyPair proto.KeyPair, vrf []byte, | ||
| ) (State, Async, error) { | ||
| height, heightErr := a.baseInfo.storage.Height() | ||
| if heightErr != nil { | ||
| return a, nil, a.Errorf(heightErr) | ||
| height, err := a.baseInfo.storage.Height() | ||
| if err != nil { | ||
| return a, nil, a.Errorf(err) | ||
| } | ||
| ngActivated, err := a.baseInfo.storage.IsActiveAtHeight(int16(settings.NG), height) | ||
| if err != nil { | ||
| return a, nil, a.Errorf(err) | ||
| } | ||
| if ngActivated { | ||
| slog.Debug("Skipping mined block in Sync state because NG is already active", "state", a.String()) | ||
| return a, nil, nil | ||
|
Comment on lines
+214
to
+224
|
||
| } | ||
| metrics.BlockMined(block) | ||
| a.baseInfo.logger.Info("New block mined", "state", a.String(), "blockID", block.ID.String()) | ||
|
|
||
| _, err := a.baseInfo.blocksApplier.Apply( | ||
| a.baseInfo.storage, | ||
| []*proto.Block{block}, | ||
| ) | ||
| if err != nil { | ||
| slog.Warn("Failed to apply mined block", slog.String("state", a.String()), logging.Error(err)) | ||
| if _, apErr := a.baseInfo.blocksApplier.Apply(a.baseInfo.storage, []*proto.Block{block}); apErr != nil { | ||
| slog.Warn("Failed to apply mined block", slog.String("state", a.String()), logging.Error(apErr)) | ||
| return a, nil, nil // We've failed to apply mined block, it's not an error | ||
| } | ||
| metrics.BlockAppliedFromExtension(block, height+1) | ||
| metrics.BlockApplied(block, height+1) | ||
| a.baseInfo.scheduler.Reschedule() | ||
|
|
||
| // first we should send block | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,8 +58,8 @@ func (msg *EndorsementCryptoMessage) Bytes() ([]byte, error) { | |
| // BlockEndorsement represents an endorsement of a block by a validator. | ||
| type BlockEndorsement struct { | ||
| EndorserIndex uint32 `json:"endorserIndex"` | ||
| FinalizedBlockID BlockID `json:"finalizedBlockID"` | ||
| FinalizedBlockHeight uint32 `json:"finalizedBlockHeight"` | ||
| FinalizedBlockID BlockID `json:"finalizedBlockId"` | ||
| FinalizedBlockHeight uint32 `json:"finalizedHeight"` | ||
|
Comment on lines
60
to
+62
|
||
| EndorsedBlockID BlockID `json:"endorsedBlockId"` | ||
| Signature bls.Signature `json:"signature"` | ||
| } | ||
|
|
@@ -110,10 +110,10 @@ func (e *BlockEndorsement) ToProtobuf() (*g.EndorseBlock, error) { | |
| } | ||
|
|
||
| type FinalizationVoting struct { | ||
| EndorserIndexes []uint32 `json:"endorserIndexes"` | ||
| FinalizedBlockHeight Height `json:"finalizedBlockHeight"` | ||
| EndorserIndexes []uint32 `json:"endorserIndexes,omitempty"` | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, in Scala implementation the field completely omitted if empty. |
||
| FinalizedBlockHeight Height `json:"finalizedHeight"` | ||
| AggregatedEndorsementSignature bls.Signature `json:"aggregatedEndorsementSignature"` | ||
| ConflictEndorsements []BlockEndorsement `json:"conflictEndorsements"` | ||
| ConflictEndorsements []BlockEndorsement `json:"conflictEndorsements,omitempty"` | ||
|
Comment on lines
112
to
+116
|
||
| } | ||
|
|
||
| // Validate checks that FinalizationVoting doesn't have any duplicate endorsers indexes. | ||
|
|
@@ -137,6 +137,19 @@ func (f *FinalizationVoting) Validate() error { | |
| return nil | ||
| } | ||
|
|
||
| // CheckSizes validates the sizes of finalization fields against the size of generator set. | ||
| // The number of endorsements and conflicting endorsements must not exceed the generator set size. | ||
| func (f *FinalizationVoting) CheckSizes(generatorSetSize int) error { | ||
| if ces := len(f.ConflictEndorsements); ces > generatorSetSize { | ||
| return fmt.Errorf("conflicting endorsements count %d exceeds generator set size %d", | ||
| ces, generatorSetSize) | ||
| } | ||
| if eis := len(f.EndorserIndexes); eis > generatorSetSize { | ||
| return fmt.Errorf("endorsements count %d exceeds generator set size %d", eis, generatorSetSize) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (f *FinalizationVoting) Marshal() ([]byte, error) { | ||
| endBlockProto, err := f.ToProtobuf() | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GeneratorsAtnow returns[]state.GeneratorInfodirectly. This changes the public JSON shape compared to the previous response wrapper:PublicKeyandBanwill now be exposedPublicKey,Ban), which is inconsistent with the endpoint’s existing lower-camel JSON convention.If the intent is to expose only
address,balance, andtransactionID(or to keep stable field naming), consider keeping an explicit response DTO / adding JSON tags (orjson:"-") on fields that should not be part of the API contract.