Skip to content

Node api finality#1897

Merged
esuwu merged 71 commits intoadd-network-messagesfrom
node-api-finality
Feb 3, 2026
Merged

Node api finality#1897
esuwu merged 71 commits intoadd-network-messagesfrom
node-api-finality

Conversation

@esuwu
Copy link
Contributor

@esuwu esuwu commented Nov 11, 2025

No description provided.

@esuwu esuwu requested a review from alexeykiselev November 24, 2025 09:13
func (s Stub) SignTransactionWith(pk crypto.PublicKey, tx proto.Transaction) error {
panic("Stub.SignTransactionWith: Unsupported operation")
func (s Stub) SignTransactionWith(_ crypto.PublicKey, _ proto.Transaction) error {
panic("Stub.SignTransactionWith: Unsopported operation")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the word “unsOpported” exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return crypto.PublicKey{}, ErrPublicKeyNotFound
}

func (a *EmbeddedWalletImpl) BlsPairByWavesPK(publicKey crypto.PublicKey) (bls.SecretKey, bls.PublicKey, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Bls" should be "BLS".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


// FindEndorserPKsByIndexes returns BLS endorser public keys using
// commitment indexes stored in FinalizationVoting.EndorserIndexes.
func (c *commitments) FindEndorserPKsByIndexes(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "PKs" and "indexes", not "PK" and "index", the function returns only one public key and accepts only one index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

"github.com/wavesplatform/gowaves/pkg/proto"
)

const finalizationKey = "finalization"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All keys have to be introduced in

commitmentKeyPrefix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

var ErrNoFinalizationHistory = errors.New("no finalization in history")

type finalizationItem struct {
Block proto.BlockHeader `cbor:"0,keyasint,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to store block header second time here, can be retrieved by height or blockID.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

func (fr *finalizationRecord) unmarshalBinary(data []byte) error { return cbor.Unmarshal(data, fr) }

type finalizations struct {
hs *historyStorage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed the finalization storage should not be a history storage. In case of using history the rollback will happen automatically, but the idea of finalization records that they are irreversible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The finalization now contains only one item, I kept the history storage. Moved it to the other PR

return false, fmt.Errorf("failed to build endorsement message: %w", err)
}

// 2. Восстанавливаем endorser PK по индексам
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no! Please use English only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

return nil
}

func (a *txAppender) isLastBlockFinalized(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange naming, is it better to name the function "updateFinalization" or "calculateFinalization"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

if err != nil {
return false, err
}
msg, err := proto.EndorsementMessage(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why construct an endorsement message here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see, it's for block header validation. I'd rather move this function to proto package, somewhere near block declaration or even made it a part of Block type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which file are you suggesting to move it to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this function EndorsementMessage is already in proto

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corresponding `pkg/client' parts have to be implemented.

@esuwu
Copy link
Contributor Author

esuwu commented Dec 3, 2025

Moved storage to add-network-messages

Comment on lines +934 to +937
activationHeight, err := a.state.ActivationHeight(int16(settings.DeterministicFinality))
if err != nil {
return fmt.Errorf("failed to get DeterministicFinality activation height: %w", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if activation height is unknown at the moment? I think the endpoint returns 500 error in such case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any changes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be handled properly.

Comment on lines +921 to +925
type GeneratorInfo struct {
Address string `json:"address"`
Balance uint64 `json:"balance"`
TransactionID string `json:"transactionID"`
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct must be package private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now used in 2 different packages

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it's an implementation details of our API. It should not be exported to the client packages.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@nickeskov nickeskov requested a review from Copilot December 17, 2025 22:59
Copy link
Collaborator

@nickeskov nickeskov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, check comments for pkg/api/node_api.go.

Comment on lines +934 to +937
activationHeight, err := a.state.ActivationHeight(int16(settings.DeterministicFinality))
if err != nil {
return fmt.Errorf("failed to get DeterministicFinality activation height: %w", err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be handled properly.

Comment on lines +939 to +940
periodStart, err := state.CurrentGenerationPeriodStart(activationHeight, height,
a.app.settings.GenerationPeriod)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be handled properly.

@esuwu esuwu merged commit 0969bcb into add-network-messages Feb 3, 2026
9 checks passed
@esuwu esuwu deleted the node-api-finality branch February 3, 2026 15:58
alexeykiselev added a commit that referenced this pull request Feb 17, 2026
* Added bls signature methods

* Added comments

* Enforced no duplicates in signatures and public keys

* Fixed linter issues

* Added pop method

* Added public key validation

* Added block finality schemas

* Added protobuf schemas

* Updated protobuf generated files

* Gosec option to exclued generated files added to security workflow.

* Set protobuf-schemas submodule to track the branch.

Submodule updated to the latest commit.

* Generated protobuf code updated to the latest schema.

* WIP: Basic structure of CommitToGeneration transaction implemented.

* BLS package refactoring.

Package renamed from blssig to bls.
Crypto primitives SecretKey, PublicKey and Signature were added.
Public functions Sing and Verify reimplemented to use new primitives.
Function to create aggregated signature from multiple Waves secrets keys
was removed because it was useful only in tests.
PoP functions moved to separate file.

* Added test on keys, signature and messages collected from Scala.

* Added tests on PoP functions.
Fixed review issues.

* Fixed linter issues.

* Protobuf schemas updated and code regenerated.

* Tidy go modules.

* Some transactions fields renamed according to Protobuf schema.
BLS package used to validate PoP during transaction validation.

* Protobuf conversion for CommitToGeneration transaction implemented.
Test on Protobuf round-trip added.

* Introduced constants for Protobuf versions of transactions
Reduced cognitive complexity of the new test.

* Added test on validation of CommitToGeneration transaction.
Added test on JSON serialization of new transaction.
WIP: added skipped test on Scala compatibility of JSON serialization.

* WIP: Started implementation of commitment transaction conversion into Ride object.
Refactored  Encode2CBigInt function.

* Returned usage of a constant.

* Finished endorsement pool

* Added endorsement handling to ng

* Finalized when key block arrives

* Fixed linter issues

* WIP: Generation Period length added to functionality settings.
BLS keys added to test global variables.
Minimal fee amount added for CommitToGeneration transaction.
Constants introduced for other fees.
Function to calculate next generation period start implemented and tested.
Basic checks of CommitToGeneration transaction against state implemented and tested.

* WIP: Commitments storage added to state. Basic functions implemented.
Commitments serialization implemented and tested.
Checks of CommitToGeneration transaction against storage of commitments added to transaction checker.
Tests on new checks implemented.
New setting MaxGenerators added to networks configurations.
StageNet settings updated.

* Modernize issues fixed.

* Fixed pr issues

* Changed the way of calculation of generation period start.
Tests updated and added.

* Returned a pointer

* Change CommitToGeneration transaction number to 19.

* TransactionType stringer fixed.
Test on JSON serialization fixed.

* Review issues fixed.
Unused fields and arguments removed.
Data emptiness by length check added.
Error messages improved and tests updated.
Compile time interface check added.

* Fixed for tests

* Added dummy implementation of some methods

* WIP: Transaction differ for CommitToGeneration transaction implementation started.
New snapshot type GenerationCommitmentSnapshot added.
Snapshot hashing for new snapshot type implemented.

* Added endorse block to actions

* Fixed the activation check

* Functions newestExists and newestSize added to commitments storage.
Test on CommitToGeneration transaction performer added.

* WIP: CBOR balances serialization implemented.

* Balances calculation fixed.
Linter issues fixed.

* Added conversion of LeaseIn and LeaseOut to int64 with overflow. Warning on such conversions added.

* Added conflict endorsements, fixed endorser commitment records, sorted endorsers records, added actions messages

* Added an endorsement message test

* Fixed 'more or less' in voting finalization

* Benchmark on wavesBalanceRecord serialization/deserialization added.

* Deprecated functions replaced.

* Updated go-safecast package to v2.

* Fixed errors check in commitments storage.

* Fixed PR issues

* Fixed linter issues

* Replaced array to heap

* Updated microblock

* Updateed protobuf schemas

* Regenerated proto structures

* Added a test

* Fixed empty endorsers when finalizing for microblock

* Updated bls signature type in finalization and endorsements

* Updated protobuf schemas

* regenerated proto structures

* Fixed serializing

* Added a feature check before adding fin to microblock

* Reset Deposits upon generation period end. (#1882)

* WIP: Reset Deposits upon generation period end.
Functions to calculate generation periods start and end added and modified according to Scala implementation.
Tests updated and added.
Function to detect generation period end added.
Function to reset deposits added.

* WIP: Integration test on CommitToGenerationTransaction and deposits resets added.
Interagation tests NodeUniversalClient improved.
New BlockchainOptions added.
BLS keys generation and storing added to itests AccountInfo.
BLS Sigrnature JSON deserialization fixed.
CommitToGenerationTransaction type added to GuessTransactionType function.
MaxGenerators field of FunctionalitySettings renamed to MaxEndorsements.
Support for new transaction added to txAppender.
Deposit application added to snapshot application of CommitToGeneration transaction.
Check on commitments limit for generation period removed. Compliment test removed.
Linter fixes.

* Excessive logging removed.

* Test on deposit rollback added.
Test made independent of starting height.

* Review issues fixed.
Few TODOs resolved.
Size functions of commitments storage removed.
Safe addition of deposit added.
Generation period end function used in state to check if generation period is over.

* Key generation options added for BLS secret key generation. (#1910)

Options to set custom salt or random salt added.
Option to set key info added.
Tests on key generation added.

* Check on repeated usage of endorser public key from another waves account added.
Duplicated code extracted in a function.
Test added.

* Fixed a mistake

* Added a check whether the endorsement pool is empy

* Update legacy state hash (#1901)

* WIP: Reset Deposits upon generation period end.
Functions to calculate generation periods start and end added and modified according to Scala implementation.
Tests updated and added.
Function to detect generation period end added.
Function to reset deposits added.

* WIP: Integration test on CommitToGenerationTransaction and deposits resets added.
Interagation tests NodeUniversalClient improved.
New BlockchainOptions added.
BLS keys generation and storing added to itests AccountInfo.
BLS Sigrnature JSON deserialization fixed.
CommitToGenerationTransaction type added to GuessTransactionType function.
MaxGenerators field of FunctionalitySettings renamed to MaxEndorsements.
Support for new transaction added to txAppender.
Deposit application added to snapshot application of CommitToGeneration transaction.
Check on commitments limit for generation period removed. Compliment test removed.
Linter fixes.

* Excessive logging removed.

* Test on deposit rollback added.
Test made independent of starting height.

* WIP: Legacy state hash structures moved to separate file.
Refactoring of structures in progress.

* StateHash structure renamed to StateHashV1.
Second version of StateHash with additional field implemented as StateHashV2.
Tests on state hash moved to separate file.
Total hash generation reimplemented with WriteTo function.
Binary serialization of StateHashV1 reimplemented with ReadFrom and WriteTo functions.
Wrapper SizedBlockID added to support serialization/deserialization of BlockID prepended with length.

* StateHashDebug interface added.
Both implementations updated accordingly.
Debug API and statehash utility updated to produce and use new interface.
BaseTarget reporting added to StateHashDebugV2.

* Required getters added to StateHash interface and implementations.
HTTP client debug updated to use proto.StateHash interface.
Itest HTTP client updated.
Utility statecmp updated and refactored a bit.

* StateHash version selection upon finality activation implemented.
WIP: Broken test added.

* Legacy state hash Scala compatibility test implemented.

* Linter issue fixed.

* Test fixed.

* Review issues fixed.
UnmarshalBinary added to StateHash interface.
Constructors to create appropriate state hashes added.
Test added.
Save of state hash fixed.

* Removed finalization on key block

* Fixed test

* Added finalization storage

* Fixed a panic

* Removed extra fields go mod

* Added punishment for conflict endorsements

* Pulled latest changes from protobuf-schemas

* Fixed a merging error

* Regenerated proto files

* Updated protobuf gen files version

* Added extra lines at the end of files

* Added one more line at the end of file

* Fixed timing of removing bad generator

* Added finalization debug logs

* Removed a line

* Added block endorsement from miner when received key block

* Changed block to parent block to endorse

* Moved sending endorsement from mining key block to receiving key block

* Added cleaning endorsement pool upon receiving key block

* Fixed a mistake with building message for signature

* Fixed a mistake with comparing endorsement messages

* Fixed FinalizedBlockHeight field

* Added a check whether addresses are in the commitment records before endorsing

* Added more meaningful errors

* Added the number of args of fsm event validation

* Added a comma

* Added a check on max_endorsements

* Removed useless code

* Fixed logging of new finalization voting

* Fixed logging of new finalization voting

* Fixed retrieving finalized blockIDs

* Fixed a log

* Fixed underflow bug with calculating finalized height

* Fixed a formatting issue

* Added logs when key not found in commitment records

* Added endorsementIDs cache

* Added logs with endorsers

* Fixed finalized height calculation

* Fixed linter issues

* Added a test for commitments

* Fixed the block signature bug where finalization was added after block was signed

* Added block generator balance to the total endorsers balance

* Added a clearer log message to get block action

* Added saving of block generator to endorsement pool

* Added block generator to endorsement pool upon receiving new block

* Fixed a bug with microblock protobuf not having finalization voting

* Added finalization voting for microblock in other places

* Added more meaningful logs and errors

* Microblock finalization is nil if block finalization is nil

* Added more logs

* removed useless calculation

* removed merging lines

* Added more logs

* Added missing finalization voting in missing conversion

* Removed fixed size from finalizatiom history record

* Removed fixed size from finalizatiom history record

* Added more logs

* Fixed finalization signature check over grandparent's block

* Fixed a linter error

* Checking generating balance on previous height instead of latest

* Checking generating balance on previous height instead of latest

* Stored the correct endorsed block height instead of the current one when finalized

* Split big function into 2

* Committed generators balances legacy state hash (#1978)

* Add legacy state hash methods for 'commitments'.

* Refactoring of 'NewLegacyStateHash' constructor.

* Add committed generators balances hash calculation.

* Add new field to statehash calculation, tests updated.

* Outdated comments updated.
Uninformative comments removed.

---------

Co-authored-by: Alexey Kiselev <alexey.kiselev@gmail.com>

* Wrapped an error

* Added limit to auto rollback according to the finality spec

* Added limit to auto rollback according to the finality spec

* Node api finality (#1897)

* Drafted endpoints for API

* Updated protobuf structures

* Added finalization storage

* Fixed errors

* Fixed old code

* SignCommitGeneration draft

* Finished signCommitToGeneration

* Added finalization validation

* Added a finalization processor for tx appender

* Merged again

* Added clients methods

* Added http client itests

* Fixed an error

* Updated protobuf version

* Implemented nickeskov's suggestions

* Implemented some AI suggestions

* Made the tx signing handle all tx types

* Fixed an fmt error

* Added a test for transactionSign

* Fixed linter erors

* Added a specific error

* Added logs

* Fixed a linter error

* Changed commitment transaction fee

* Allowed for custom transaction fee in commitment tx sign api

* Fix modernize.

* Changed fmt to errors wrap

---------

Co-authored-by: Nikolay Eskov <mr.eskov1@yandex.ru>

* Linter issues fixed.

* Auto rollback finalization 2 (#2005)

* Added a soft rollback

* Added commit after saving finalization after rollback

* Added a check whether finalization block exists

* Changed newest block id by height

* Set currentBlockID when finalization is set

* Fixed PR issues

* Fixed a typo

* Modernize issue fixed.

---------

Co-authored-by: esuwu <sanya554455@gmail.com>

---------

Co-authored-by: Alexey Kiselev <alexey.kiselev@gmail.com>
Co-authored-by: Nikolay Eskov <mr.eskov1@yandex.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants