Skip to content
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
6 changes: 4 additions & 2 deletions pkg/node/fsm/ng_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (

"github.com/pkg/errors"
"github.com/qmuntal/stateless"

"github.com/wavesplatform/gowaves/pkg/crypto"

"github.com/ccoveille/go-safecast/v2"

"github.com/wavesplatform/gowaves/pkg/crypto/bls"
"github.com/wavesplatform/gowaves/pkg/logging"
"github.com/wavesplatform/gowaves/pkg/metrics"
Expand Down Expand Up @@ -810,9 +812,9 @@ func (a *NGState) checkAndAppendMicroBlock(
return nil, errors.Errorf("microblock '%s' has invalid signature", micro.TotalBlockID.String())
}
newTrs := top.Transactions.Join(micro.Transactions)
fv := proto.CombineFinalizationVoting(top.FinalizationVoting, micro.PartialFinalization)
newBlock, err := proto.CreateBlock(newTrs, top.Timestamp, top.Parent, top.GeneratorPublicKey, top.NxtConsensus,
top.Version, top.Features, top.RewardVote, a.baseInfo.scheme, micro.StateHash,
micro.PartialFinalization)
top.Version, top.Features, top.RewardVote, a.baseInfo.scheme, micro.StateHash, fv)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/node/fsm/wait_micro_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@ func (a *WaitMicroSnapshotState) checkAndAppendMicroBlock(
return nil, errors.Errorf("microblock '%s' has invalid signature", micro.TotalBlockID.String())
}
newTrs := top.Transactions.Join(micro.Transactions)
fv := proto.CombineFinalizationVoting(top.FinalizationVoting, micro.PartialFinalization)
newBlock, err := proto.CreateBlock(newTrs, top.Timestamp, top.Parent, top.GeneratorPublicKey, top.NxtConsensus,
top.Version, top.Features, top.RewardVote, a.baseInfo.scheme, micro.StateHash, micro.PartialFinalization)
top.Version, top.Features, top.RewardVote, a.baseInfo.scheme, micro.StateHash, fv)
if err != nil {
return nil, err
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/proto/finalization.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package proto
import (
"encoding/binary"
"log/slog"
"slices"

"github.com/ccoveille/go-safecast/v2"
"github.com/pkg/errors"
Expand Down Expand Up @@ -146,6 +147,21 @@ func (f *FinalizationVoting) ToProtobuf() (*g.FinalizationVoting, error) {
return &finalizationVoting, nil
}

func CombineFinalizationVoting(voting1, voting2 *FinalizationVoting) *FinalizationVoting {
switch {
case voting1 == nil && voting2 == nil:
return nil
case voting1 == nil:
return voting2
case voting2 == nil:
return voting1
default:
res := *voting2
res.ConflictEndorsements = slices.Concat(voting1.ConflictEndorsements, voting2.ConflictEndorsements)
return &res
}
}

func CalculateLastFinalizedHeight(currentHeight Height) Height {
var genesisHeight uint64 = 1
var maxRollbackDeltaHeight uint64 = 100
Expand Down
94 changes: 94 additions & 0 deletions pkg/proto/finalization_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package proto_test

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"

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

func TestFinalizationVotingCombination(t *testing.T) {
fv1 := &proto.FinalizationVoting{
EndorserIndexes: []int32{0, 1, 2},
FinalizedBlockHeight: 123,
AggregatedEndorsementSignature: bls.Signature{},
ConflictEndorsements: nil,
}
fv2 := &proto.FinalizationVoting{
EndorserIndexes: []int32{3, 4, 5},
FinalizedBlockHeight: 123,
AggregatedEndorsementSignature: bls.Signature{},
ConflictEndorsements: nil,
}
eb1 := proto.EndorseBlock{
EndorserIndex: 0,
FinalizedBlockID: proto.MustBlockIDFromBase58("4L1nScCRDdRkvVHwrhubtQtn5n7EWh68WFn6oZMt8KHW"),
FinalizedBlockHeight: 123,
EndorsedBlockID: proto.MustBlockIDFromBase58("7rm2AyHHb2iud2hqid2jVD8z4cJ8iAuWQoAQ441VvfVc"),
Signature: bls.Signature{},
}
eb2 := proto.EndorseBlock{
EndorserIndex: 1,
FinalizedBlockID: proto.MustBlockIDFromBase58("4L1nScCRDdRkvVHwrhubtQtn5n7EWh68WFn6oZMt8KHW"),
FinalizedBlockHeight: 123,
EndorsedBlockID: proto.MustBlockIDFromBase58("7rm2AyHHb2iud2hqid2jVD8z4cJ8iAuWQoAQ441VvfVc"),
Signature: bls.Signature{},
}
fv1c := &proto.FinalizationVoting{
EndorserIndexes: []int32{0, 1, 2},
FinalizedBlockHeight: 123,
AggregatedEndorsementSignature: bls.Signature{},
ConflictEndorsements: []proto.EndorseBlock{eb1},
}
fv2c := &proto.FinalizationVoting{
EndorserIndexes: []int32{3, 4, 5},
FinalizedBlockHeight: 123,
AggregatedEndorsementSignature: bls.Signature{},
ConflictEndorsements: []proto.EndorseBlock{eb2},
}
for i, test := range []struct {
fv1 *proto.FinalizationVoting
fv2 *proto.FinalizationVoting
res *proto.FinalizationVoting
}{
{fv1, fv2, fv2},
{nil, fv2, fv2},
{fv1, nil, fv1},
{nil, nil, nil},
{nil, fv2c, fv2c},
{fv1c, nil, fv1c},
{fv1c, fv2c,
&proto.FinalizationVoting{
EndorserIndexes: []int32{3, 4, 5},
FinalizedBlockHeight: 123,
AggregatedEndorsementSignature: bls.Signature{},
ConflictEndorsements: []proto.EndorseBlock{eb1, eb2},
},
},
{fv2c, fv1c,
&proto.FinalizationVoting{
EndorserIndexes: []int32{0, 1, 2},
FinalizedBlockHeight: 123,
AggregatedEndorsementSignature: bls.Signature{},
ConflictEndorsements: []proto.EndorseBlock{eb2, eb1},
},
},
{fv1, fv2c, fv2c},
{fv1c, fv2,
&proto.FinalizationVoting{
EndorserIndexes: []int32{3, 4, 5},
FinalizedBlockHeight: 123,
AggregatedEndorsementSignature: bls.Signature{},
ConflictEndorsements: []proto.EndorseBlock{eb1},
},
},
} {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
r := proto.CombineFinalizationVoting(test.fv1, test.fv2)
assert.Equal(t, test.res, r)
})
}
}
Loading