Skip to content

Commit

Permalink
Merge pull request #279 from multiversx/proof_on_hdrv2
Browse files Browse the repository at this point in the history
Proof on header v2
  • Loading branch information
sstanculeanu authored Jan 4, 2024
2 parents a1e7279 + 1b69f48 commit 81c3fde
Show file tree
Hide file tree
Showing 12 changed files with 722 additions and 212 deletions.
13 changes: 12 additions & 1 deletion data/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var _ = data.HeaderHandler(&Header{})
var _ = data.ShardHeaderHandler(&Header{})

// MiniBlockSlice should be used when referring to subset of mini blocks that is not
// necessarily representing a full block body
// necessarily representing a full block body
type MiniBlockSlice []*MiniBlock

// MiniblockAndHash holds the info related to a miniblock and its hash
Expand Down Expand Up @@ -615,3 +615,14 @@ func (h *Header) CheckFieldsForNil() error {

return nil
}

// GetPreviousAggregatedSignatureAndBitmap returns the previous aggregated signature and the previous pubkeys bitmap
func (h *Header) GetPreviousAggregatedSignatureAndBitmap() ([]byte, []byte) {
// no proof for the initial header
return nil, nil
}

// SetPreviousAggregatedSignatureAndBitmap sets the previous aggregated signature and the previous pubkeys bitmap
func (h *Header) SetPreviousAggregatedSignatureAndBitmap(_ []byte, _ []byte) {
// no proof for the initial header
}
16 changes: 16 additions & 0 deletions data/block/blockV2.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,19 @@ func (hv2 *HeaderV2) CheckFieldsForNil() error {

return nil
}

// GetPreviousAggregatedSignatureAndBitmap returns the previous aggregated signature and the previous pubkeys bitmap
func (hv2 *HeaderV2) GetPreviousAggregatedSignatureAndBitmap() ([]byte, []byte) {
if hv2.PreviousHeaderProof == nil {
return nil, nil
}
return hv2.PreviousHeaderProof.AggregatedSignature, hv2.PreviousHeaderProof.PubKeysBitmap
}

// SetPreviousAggregatedSignatureAndBitmap sets the previous aggregated signature and the previous pubkeys bitmap
func (hv2 *HeaderV2) SetPreviousAggregatedSignatureAndBitmap(aggregatedSignature []byte, pubKeysBitmap []byte) {
hv2.PreviousHeaderProof = &PreviousHeaderProof{
PubKeysBitmap: pubKeysBitmap,
AggregatedSignature: aggregatedSignature,
}
}
442 changes: 394 additions & 48 deletions data/block/blockV2.pb.go

Large diffs are not rendered by default.

21 changes: 14 additions & 7 deletions data/block/blockV2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import "block.proto";

// HeaderV2 extends the Header structure with extra fields for version 2
message HeaderV2 {
Header Header = 1 [(gogoproto.jsontag) = "header,omitempty"];
bytes ScheduledRootHash = 2 [(gogoproto.jsontag) = "scheduledRootHash,omitempty"];
bytes ScheduledAccumulatedFees = 3 [(gogoproto.jsontag) = "scheduledAccumulatedFees,omitempty", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"];
bytes ScheduledDeveloperFees = 4 [(gogoproto.jsontag) = "scheduledDeveloperFees,omitempty", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"];
uint64 ScheduledGasProvided = 5 [(gogoproto.jsontag) = "scheduledGasProvided"];
uint64 ScheduledGasPenalized = 6 [(gogoproto.jsontag) = "scheduledGasPenalized"];
uint64 ScheduledGasRefunded = 7 [(gogoproto.jsontag) = "scheduledGasRefunded"];
Header Header = 1 [(gogoproto.jsontag) = "header,omitempty"];
bytes ScheduledRootHash = 2 [(gogoproto.jsontag) = "scheduledRootHash,omitempty"];
bytes ScheduledAccumulatedFees = 3 [(gogoproto.jsontag) = "scheduledAccumulatedFees,omitempty", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"];
bytes ScheduledDeveloperFees = 4 [(gogoproto.jsontag) = "scheduledDeveloperFees,omitempty", (gogoproto.casttypewith) = "math/big.Int;github.com/multiversx/mx-chain-core-go/data.BigIntCaster"];
uint64 ScheduledGasProvided = 5 [(gogoproto.jsontag) = "scheduledGasProvided"];
uint64 ScheduledGasPenalized = 6 [(gogoproto.jsontag) = "scheduledGasPenalized"];
uint64 ScheduledGasRefunded = 7 [(gogoproto.jsontag) = "scheduledGasRefunded"];
PreviousHeaderProof PreviousHeaderProof = 8 [(gogoproto.jsontag) = "previousHeaderProof"];
}

message MiniBlockReserved {
Expand All @@ -31,3 +32,9 @@ message MiniBlockHeaderReserved {
int32 IndexOfFirstTxProcessed = 3 [(gogoproto.jsontag) = "indexOfFirstTxProcessed"];
int32 IndexOfLastTxProcessed = 4 [(gogoproto.jsontag) = "indexOfLastTxProcessed"];
}

// PreviousHeaderProof defines a header proof
message PreviousHeaderProof {
bytes PubKeysBitmap = 1 [(gogoproto.jsontag) = "pubKeysBitmap"];
bytes AggregatedSignature = 2 [(gogoproto.jsontag) = "aggregatedSignature"];
}
4 changes: 3 additions & 1 deletion data/block/blockV2Checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
var headerV2ExceptionFields = []string{
"Header",
"ScheduledRootHash",
"PreviousHeaderProof",
}

func TestBlockHeaderV2_Checks(t *testing.T) {
Expand Down Expand Up @@ -68,7 +69,8 @@ func TestBlockHeaderV2_Checks(t *testing.T) {
t.Parallel()

objectToTest := &HeaderV2{
Header: &Header{},
Header: &Header{},
PreviousHeaderProof: &PreviousHeaderProof{},
}

fieldsForHeaderV1 := prepareFieldsList(objectToTest.Header, headerV1ExceptionFields...)
Expand Down
17 changes: 17 additions & 0 deletions data/block/blockV2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,3 +1217,20 @@ func TestHeaderV2_HasScheduledMiniBlocks(t *testing.T) {

require.False(t, shardBlock.HasScheduledMiniBlocks())
}

func TestHeaderV2_GetPreviousAggregatedSignatureAndBitmap(t *testing.T) {
t.Parallel()

shardBlock := &block.HeaderV2{}
sig, bitmap := shardBlock.GetPreviousAggregatedSignatureAndBitmap()
require.Nil(t, sig)
require.Nil(t, bitmap)

previousPubkeysBitmap := []byte("previous pub keys bitmap")
previousAggregatedSignature := []byte("previous aggregated signature")

shardBlock.SetPreviousAggregatedSignatureAndBitmap(previousAggregatedSignature, previousPubkeysBitmap)
sig, bitmap = shardBlock.GetPreviousAggregatedSignatureAndBitmap()
require.Equal(t, previousPubkeysBitmap, bitmap)
require.Equal(t, previousAggregatedSignature, sig)
}
16 changes: 16 additions & 0 deletions data/block/metaBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,3 +566,19 @@ func (m *MetaBlock) CheckFieldsForNil() error {

return nil
}

// GetPreviousAggregatedSignatureAndBitmap returns the previous aggregated signature and the previous pubkeys bitmap
func (m *MetaBlock) GetPreviousAggregatedSignatureAndBitmap() ([]byte, []byte) {
if m.PreviousHeaderProof == nil {
return nil, nil
}
return m.PreviousHeaderProof.AggregatedSignature, m.PreviousHeaderProof.PubKeysBitmap
}

// SetPreviousAggregatedSignatureAndBitmap sets the previous aggregated signature and the previous pubkeys bitmap
func (m *MetaBlock) SetPreviousAggregatedSignatureAndBitmap(aggregatedSignature []byte, pubKeysBitmap []byte) {
m.PreviousHeaderProof = &PreviousHeaderProof{
PubKeysBitmap: pubKeysBitmap,
AggregatedSignature: aggregatedSignature,
}
}
Loading

0 comments on commit 81c3fde

Please sign in to comment.