Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
29f4d7b
Added bls signature methods
esuwu Aug 29, 2025
d77508d
Merge branch 'master' into bls-aggregated-sig
esuwu Aug 29, 2025
343c381
Added comments
esuwu Aug 29, 2025
03d4cf5
Enforced no duplicates in signatures and public keys
esuwu Aug 29, 2025
6840745
Fixed linter issues
esuwu Aug 29, 2025
101fb33
Added pop method
esuwu Sep 12, 2025
7ea94e1
Added public key validation
esuwu Sep 15, 2025
aa60bf9
Added block finality schemas
esuwu Sep 19, 2025
c2050d8
Added protobuf schemas
esuwu Sep 19, 2025
1422256
Merge branch 'master' into add-finalization-proto-schemas
esuwu Sep 19, 2025
cf7abf1
Updated protobuf generated files
esuwu Sep 19, 2025
9d29d63
Gosec option to exclued generated files added to security workflow.
alexeykiselev Sep 22, 2025
6842edb
Set protobuf-schemas submodule to track the branch.
alexeykiselev Sep 22, 2025
c528208
Generated protobuf code updated to the latest schema.
alexeykiselev Sep 22, 2025
f583bcf
Merge branch 'determenistic-finality-feature' into add-finalization-p…
alexeykiselev Sep 22, 2025
fb0d4ca
WIP: Basic structure of CommitToGeneration transaction implemented.
alexeykiselev Sep 22, 2025
9091c0f
Merge branch 'determenistic-finality-feature' into bls-aggregated-sig
alexeykiselev Sep 22, 2025
b4f94b3
BLS package refactoring.
alexeykiselev Sep 23, 2025
bf8e011
Added test on keys, signature and messages collected from Scala.
alexeykiselev Sep 23, 2025
e61cea9
Added tests on PoP functions.
alexeykiselev Sep 24, 2025
7cb5772
Fixed linter issues.
alexeykiselev Sep 24, 2025
c954547
Protobuf schemas updated and code regenerated.
alexeykiselev Sep 24, 2025
7b30cf3
Merge branch 'determenistic-finality-feature' into add-finalization-p…
alexeykiselev Sep 24, 2025
3fd39ea
Tidy go modules.
alexeykiselev Sep 24, 2025
66dceac
Merge branch 'add-finalization-proto-schemas' into add-commit-to-gene…
alexeykiselev Sep 25, 2025
b800d5b
Merge branch 'bls-aggregated-sig-refactoring' into add-commit-to-gene…
alexeykiselev Sep 25, 2025
83e29f3
Some transactions fields renamed according to Protobuf schema.
alexeykiselev Sep 25, 2025
47b2fa1
Protobuf conversion for CommitToGeneration transaction implemented.
alexeykiselev Sep 25, 2025
28ff6f0
Introduced constants for Protobuf versions of transactions
alexeykiselev Sep 25, 2025
a6f3e63
Added test on validation of CommitToGeneration transaction.
alexeykiselev Sep 25, 2025
1757aa8
WIP: Started implementation of commitment transaction conversion into…
alexeykiselev Sep 29, 2025
966ef36
Returned usage of a constant.
alexeykiselev Sep 29, 2025
58c37b2
Finished endorsement pool
esuwu Sep 30, 2025
06e6a1e
Merged from finality branch
esuwu Sep 30, 2025
cdfa0fa
Added endorsement handling to ng
esuwu Sep 30, 2025
fd9a7e4
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Oct 1, 2025
4f49217
Finalized when key block arrives
esuwu Oct 6, 2025
dc85bf7
Fixed linter issues
esuwu Oct 6, 2025
8f4c8cb
WIP: Generation Period length added to functionality settings.
alexeykiselev Oct 6, 2025
9619261
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Oct 6, 2025
8b0ac77
WIP: Commitments storage added to state. Basic functions implemented.
alexeykiselev Oct 8, 2025
00ebe4f
Modernize issues fixed.
alexeykiselev Oct 8, 2025
494b343
Fixed pr issues
esuwu Oct 10, 2025
2dd89c0
Changed the way of calculation of generation period start.
alexeykiselev Oct 10, 2025
1d0f2a6
Returned a pointer
esuwu Oct 10, 2025
853ceae
Change CommitToGeneration transaction number to 19.
alexeykiselev Oct 10, 2025
cc5b328
TransactionType stringer fixed.
alexeykiselev Oct 10, 2025
6494602
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Oct 10, 2025
9334614
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Oct 15, 2025
3d69c49
Review issues fixed.
alexeykiselev Oct 15, 2025
53ba501
Fixed for tests
esuwu Oct 15, 2025
fe385c3
Merged from add-commit-to-generation-transaction
esuwu Oct 15, 2025
81f8c15
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Oct 15, 2025
2b1c2c8
Added dummy implementation of some methods
esuwu Oct 16, 2025
762cf8a
WIP: Transaction differ for CommitToGeneration transaction implementa…
alexeykiselev Oct 16, 2025
ac827c4
Added endorse block to actions
esuwu Oct 16, 2025
bde5f02
Fixed the activation check
esuwu Oct 16, 2025
0199c4b
Functions newestExists and newestSize added to commitments storage.
alexeykiselev Oct 20, 2025
40a3dc0
WIP: CBOR balances serialization implemented.
alexeykiselev Oct 21, 2025
5ea90c9
Balances calculation fixed.
alexeykiselev Oct 22, 2025
986854f
Added conversion of LeaseIn and LeaseOut to int64 with overflow. Warn…
alexeykiselev Oct 22, 2025
3dc85d2
Added conflict endorsements, fixed endorser commitment records, sorte…
esuwu Oct 23, 2025
4477abd
Added an endorsement message test
esuwu Oct 23, 2025
e77b6a9
Fixed 'more or less' in voting finalization
esuwu Oct 23, 2025
c9ba16e
Benchmark on wavesBalanceRecord serialization/deserialization added.
alexeykiselev Oct 24, 2025
af387e1
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Oct 29, 2025
d79375e
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Nov 1, 2025
df9e57a
Deprecated functions replaced.
alexeykiselev Nov 1, 2025
a7b7e35
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Nov 5, 2025
48eb820
Updated go-safecast package to v2.
alexeykiselev Nov 5, 2025
539df7d
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Nov 6, 2025
cc89028
Fixed errors check in commitments storage.
alexeykiselev Nov 6, 2025
2f79146
Merged from commitment generation transaction
esuwu Nov 6, 2025
d1db683
Fixed PR issues
esuwu Nov 7, 2025
a7c60d9
Fixed linter issues
esuwu Nov 7, 2025
85cb756
Replaced array to heap
esuwu Nov 11, 2025
12788cb
Updated microblock
esuwu Nov 14, 2025
a603e34
Updateed protobuf schemas
esuwu Nov 14, 2025
07d33ec
Regenerated proto structures
esuwu Nov 14, 2025
74bc66a
Added a test
esuwu Nov 14, 2025
86e4527
Fixed empty endorsers when finalizing for microblock
esuwu Nov 14, 2025
c3ea98b
Updated bls signature type in finalization and endorsements
esuwu Nov 17, 2025
a140fd1
Updated protobuf schemas
esuwu Nov 17, 2025
eb7026d
regenerated proto structures
esuwu Nov 17, 2025
31dbe1f
Fixed serializing
esuwu Nov 17, 2025
493c90c
Added a feature check before adding fin to microblock
esuwu Nov 17, 2025
1a247b4
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Nov 18, 2025
d5ffa83
Reset Deposits upon generation period end. (#1882)
alexeykiselev Nov 18, 2025
1cb8538
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Nov 20, 2025
ce90ec9
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Nov 21, 2025
3bced1c
Key generation options added for BLS secret key generation. (#1910)
alexeykiselev Nov 21, 2025
4183c34
Check on repeated usage of endorser public key from another waves acc…
alexeykiselev Nov 24, 2025
e451270
Merged from commitment generation tx
esuwu Nov 24, 2025
36aa486
Fixed a mistake
esuwu Nov 25, 2025
f71cbe2
Added a check whether the endorsement pool is empy
esuwu Nov 25, 2025
cde8f94
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Nov 25, 2025
6107547
Merge branch 'add-commit-to-generation-transaction' into add-network-…
esuwu Nov 25, 2025
f8c4400
Update legacy state hash (#1901)
alexeykiselev Nov 26, 2025
20e076f
Removed finalization on key block
esuwu Nov 27, 2025
d1285a2
Fixed test
esuwu Dec 3, 2025
4158ae8
Added finalization storage
esuwu Dec 3, 2025
e88691a
Merged from finality transaction
esuwu Dec 3, 2025
901c065
Merge branch 'add-commit-to-generation-transaction' of github.com:wav…
esuwu Dec 3, 2025
51ed89d
Merge branch 'add-commit-to-generation-transaction' into add-network-…
esuwu Dec 3, 2025
526f116
Fixed a panic
esuwu Dec 4, 2025
16565ac
Merged from master
esuwu Dec 4, 2025
155a58b
Removed extra fields go mod
esuwu Dec 4, 2025
3234975
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
esuwu Dec 4, 2025
adb7e27
Merge branch 'add-commit-to-generation-transaction' into add-network-…
esuwu Dec 4, 2025
9ef9bb2
Merge branch 'determenistic-finality-feature' into add-commit-to-gene…
alexeykiselev Dec 5, 2025
5ff4b0b
Merge branch 'add-commit-to-generation-transaction' into add-network-…
esuwu Dec 5, 2025
d949d87
Added punishment for conflict endorsements
esuwu Dec 17, 2025
2b88563
Pulled latest changes from protobuf-schemas
esuwu Dec 17, 2025
625c094
Merged from finality feature
esuwu Dec 17, 2025
e2be554
Fixed a merging error
esuwu Dec 17, 2025
6e434d2
Regenerated proto files
esuwu Dec 17, 2025
06ec89a
Updated protobuf gen files version
esuwu Dec 18, 2025
9712cae
Added extra lines at the end of files
esuwu Dec 18, 2025
bf1f693
Added one more line at the end of file
esuwu Dec 18, 2025
dd9c0b3
Fixed timing of removing bad generator
esuwu Dec 23, 2025
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
7 changes: 5 additions & 2 deletions cmd/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/wavesplatform/gowaves/pkg/logging"
"github.com/wavesplatform/gowaves/pkg/metrics"
"github.com/wavesplatform/gowaves/pkg/miner"
"github.com/wavesplatform/gowaves/pkg/miner/endorsementpool"
"github.com/wavesplatform/gowaves/pkg/miner/scheduler"
"github.com/wavesplatform/gowaves/pkg/miner/utxpool"
"github.com/wavesplatform/gowaves/pkg/node"
Expand Down Expand Up @@ -480,7 +481,7 @@ func runNode(ctx context.Context, nc *config) (_ io.Closer, retErr error) {
return nil, errors.Wrap(apiErr, "failed to run APIs")
}

return startNode(ctx, nc, svs, features, minerScheduler, parent, declAddr, nl), nil
return startNode(ctx, nc, svs, features, minerScheduler, parent, declAddr, nl, cfg.GenerationPeriod), nil
}

func startNode(
Expand All @@ -492,6 +493,7 @@ func startNode(
parent peer.Parent,
declAddr proto.TCPAddr,
nl *slog.Logger,
periodGeneration uint64,
) *node.Node {
bindAddr := proto.NewTCPAddrFromString(nc.bindAddress)

Expand All @@ -504,7 +506,7 @@ func startNode(
go ntw.Run(ctx)

n := node.NewNode(svs, declAddr, bindAddr, nc.microblockInterval, nc.enableLightMode, nl, fl)
go n.Run(ctx, parent, svs.InternalChannel, networkInfoCh, ntw.SyncPeer())
go n.Run(ctx, parent, svs.InternalChannel, networkInfoCh, ntw.SyncPeer(), periodGeneration)
return n
}

Expand Down Expand Up @@ -813,6 +815,7 @@ func createServices(
Scheduler: scheduler,
BlocksApplier: blocks_applier.NewBlocksApplier(),
UtxPool: utxpool.New(utxPoolMaxSizeBytes, utxValidator, cfg),
EndorsementPool: endorsementpool.NewEndorsementPool(cfg.MaxEndorsements),
Scheme: cfg.AddressSchemeCharacter,
Time: ntpTime,
Wallet: wal,
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"log/slog"
"net/http"

"github.com/pkg/errors"
Expand Down Expand Up @@ -176,6 +177,7 @@ func (a *Transactions) Broadcast(ctx context.Context, transaction proto.Transact
}
}

slog.Debug("Broadcasting transaction", "transaction", string(bts))
req, err := http.NewRequest("POST", url.String(), bytes.NewReader(bts))
if err != nil {
return nil, err
Expand Down
238 changes: 238 additions & 0 deletions pkg/miner/endorsementpool/endorsement_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
package endorsementpool

import (
"bytes"
"container/heap"
"errors"
"sync"

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

type key struct {
blockID proto.BlockID
endorserIndex int32
}

func makeKey(blockID proto.BlockID, idx int32) key {
return key{blockID: blockID, endorserIndex: idx}
}

type heapItemEndorsement struct {
eb *proto.EndorseBlock
endorserPK bls.PublicKey
balance uint64
seq uint64
}

type endorsementMinHeap []*heapItemEndorsement

func (h endorsementMinHeap) Len() int { return len(h) }

func (h endorsementMinHeap) Less(i, j int) bool {
if h[i].balance == h[j].balance {
// Late (Higher seq), lower priority.
return h[i].seq > h[j].seq
}
// Lower balance, lower priority.
return h[i].balance < h[j].balance
}

func (h endorsementMinHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }

func (h *endorsementMinHeap) Push(x any) {
item, ok := x.(*heapItemEndorsement)
if !ok {
return // Impossible, but silences errcheck.
}
*h = append(*h, item)
}

func (h *endorsementMinHeap) Pop() any {
old := *h
n := len(old)
item := old[n-1]
*h = old[:n-1]
return item
}

type EndorsementPool struct {
mu sync.Mutex
seq uint64
byKey map[key]*heapItemEndorsement
h endorsementMinHeap
conflicts []proto.EndorseBlock
maxEndorsements int
}

func NewEndorsementPool(maxGenerators int) *EndorsementPool {
return &EndorsementPool{
byKey: make(map[key]*heapItemEndorsement),
maxEndorsements: maxGenerators,
}
}

// Add inserts an endorsement into the heap with priority based on balance desc, seq asc.
func (p *EndorsementPool) Add(e *proto.EndorseBlock, pk bls.PublicKey,
lastFinalizedHeight proto.Height, lastFinalizedBlockID proto.BlockID, balance uint64) error {
if e == nil {
return errors.New("invalid endorsement")
}

k := makeKey(e.EndorsedBlockID, e.EndorserIndex)

p.mu.Lock()
defer p.mu.Unlock()
if _, exists := p.byKey[k]; exists {
p.conflicts = append(p.conflicts, *e)
return nil
}
if proto.Height(e.FinalizedBlockHeight) <= lastFinalizedHeight &&
e.FinalizedBlockID != lastFinalizedBlockID {
p.conflicts = append(p.conflicts, *e)
return nil
}

p.seq++
item := &heapItemEndorsement{
eb: e,
endorserPK: pk,
balance: balance,
seq: p.seq,
}

// If heap is not filled yet.
if len(p.h) < p.maxEndorsements {
heap.Push(&p.h, item)
p.byKey[k] = item
return nil
}

// If heap is full — check min (root).
minItem := p.h[0]
// If priority is lower or equal the min, throw the new one away.
if balance < minItem.balance || (balance == minItem.balance && item.seq > minItem.seq) {
return nil
}

// Otherwise remove min and insert the new one.
r := heap.Pop(&p.h)
removed, _ := r.(*heapItemEndorsement)
delete(p.byKey, makeKey(removed.eb.EndorsedBlockID, removed.eb.EndorserIndex))

heap.Push(&p.h, item)
p.byKey[k] = item
return nil
}

func (p *EndorsementPool) GetAll() []proto.EndorseBlock {
p.mu.Lock()
defer p.mu.Unlock()

out := make([]proto.EndorseBlock, len(p.h))
for i, it := range p.h {
out[i] = *it.eb
}
return out
}

func (p *EndorsementPool) FormFinalization(finalizationHeight proto.Height) (proto.FinalizationVoting, error) {
p.mu.Lock()
defer p.mu.Unlock()

signatures := make([]bls.Signature, 0, len(p.h))
endorsersIndexes := make([]int32, 0, len(p.h))
var aggregatedSignature bls.Signature

for _, it := range p.h {
signatures = append(signatures, it.eb.Signature)
endorsersIndexes = append(endorsersIndexes, it.eb.EndorserIndex)
}
if len(signatures) != 0 {
aggregatedSignatureBytes, err := bls.AggregateSignatures(signatures)
if err != nil {
return proto.FinalizationVoting{}, err
}
var errCnvrt error
aggregatedSignature, errCnvrt = bls.NewSignatureFromBytes(aggregatedSignatureBytes)
if errCnvrt != nil {
return proto.FinalizationVoting{}, errCnvrt
}
}

return proto.FinalizationVoting{
AggregatedEndorsementSignature: aggregatedSignature,
FinalizedBlockHeight: finalizationHeight,
EndorserIndexes: endorsersIndexes,
ConflictEndorsements: p.conflicts,
}, nil
}

func (p *EndorsementPool) GetEndorsers() []bls.PublicKey {
p.mu.Lock()
defer p.mu.Unlock()

out := make([]bls.PublicKey, len(p.h))
for i, it := range p.h {
out[i] = it.endorserPK
}
return out
}

func (p *EndorsementPool) Len() int {
p.mu.Lock()
defer p.mu.Unlock()
return len(p.h)
}

func (p *EndorsementPool) CleanAll() {
p.mu.Lock()
defer p.mu.Unlock()

p.byKey = make(map[key]*heapItemEndorsement)
p.h = nil
p.conflicts = nil
}

func (p *EndorsementPool) Verify() (bool, error) {
p.mu.Lock()
defer p.mu.Unlock()

n := len(p.h)
if n == 0 {
return false, errors.New("failed to verify endorsements: pool is empty")
}

sigs := make([]bls.Signature, 0, n)
pks := make([]bls.PublicKey, 0, n)
msg, err := p.h[0].eb.EndorsementMessage()
if err != nil {
return false, err
}
for _, it := range p.h {
sigs = append(sigs, it.eb.Signature)
pks = append(pks, it.endorserPK)
nextMsg, msgErr := it.eb.EndorsementMessage()
if msgErr != nil {
return false, msgErr
}
if bytes.Equal(nextMsg, msg) {
return false, errors.New("failed to verify endorsements: inconsistent endorsement messages")
}
}
agg, err := bls.AggregateSignatures(sigs)
if err != nil {
return false, err
}
return bls.VerifyAggregate(pks, msg, agg), nil
}

func (p *EndorsementPool) ConflictEndorsements() []proto.EndorseBlock {
p.mu.Lock()
defer p.mu.Unlock()

out := make([]proto.EndorseBlock, len(p.conflicts))
copy(out, p.conflicts)
return out
}
Loading
Loading