Skip to content

Commit

Permalink
Update codec vectors to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
pantrif committed Nov 27, 2024
1 parent 83ff6e8 commit 4980c42
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 195 deletions.
4 changes: 2 additions & 2 deletions internal/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ type Block struct {
// Extrinsic represents the block extrinsic data
type Extrinsic struct {
ET TicketExtrinsic
ED DisputeExtrinsic
EP PreimageExtrinsic
EA AssurancesExtrinsic
EG GuaranteesExtrinsic
EA AssurancesExtrinsic
ED DisputeExtrinsic
}
9 changes: 5 additions & 4 deletions internal/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package block
import (
"crypto/ed25519"
"crypto/rand"
"github.com/eigerco/strawberry/pkg/serialization/codec/jam"
"testing"

"github.com/eigerco/strawberry/internal/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/eigerco/strawberry/internal/common"
"github.com/eigerco/strawberry/internal/crypto"
"github.com/eigerco/strawberry/internal/testutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/eigerco/strawberry/pkg/serialization/codec/jam"
)

func Test_BlockEncodeDecode(t *testing.T) {
Expand Down Expand Up @@ -156,6 +156,7 @@ func Test_BlockEncodeDecode(t *testing.T) {
Output: WorkResultOutputOrError{CodeTooLarge},
},
},
SegmentRootLookup: make(map[crypto.Hash]crypto.Hash),
},
Credentials: []CredentialSignature{
{
Expand Down
21 changes: 10 additions & 11 deletions internal/block/guarantee.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,31 @@ type CredentialSignature struct {
Signature [crypto.Ed25519SignatureSize]byte // The Ed25519 signature
}

// WorkReport represents a work report in the JAM state (equation 118 v0.4.5)
// WorkReport represents a work report in the JAM state (equation 11.2 v0.5.0)
// TODO: The total serialized size of a work-report may be no greater than MaxWorkPackageSizeBytes.
type WorkReport struct {
WorkPackageSpecification WorkPackageSpecification // Work-package specification (s)
RefinementContext RefinementContext // Refinement context (x)
CoreIndex uint16 // Core index (c) - Max value: TotalNumberOfCores
AuthorizerHash crypto.Hash // HeaderHash of the authorizer (a)
Output []byte // Output of the work report (o)
WorkResults []WorkResult // Results of the evaluation of each of the items in the work-package (r) - Min value: MinWorkPackageResultsSize. Max value: MaxWorkPackageResultsSize.

// TODO ignore this field for now as the test vectors still do not include it
SegmentRootLookup map[crypto.Hash]crypto.Hash `json:"-" jam:"-"` // A segment-root lookup dictionary (l ∈ D⟨H → H⟩)
WorkPackageSpecification WorkPackageSpecification // Work-package specification (s)
RefinementContext RefinementContext // Refinement context (x)
CoreIndex uint16 // Core index (c) - Max value: TotalNumberOfCores
AuthorizerHash crypto.Hash // HeaderHash of the authorizer (a)
Output []byte // Output of the work report (o)
SegmentRootLookup map[crypto.Hash]crypto.Hash // A segment-root lookup dictionary (l ∈ D⟨H → H⟩)
WorkResults []WorkResult // Results of the evaluation of each of the items in the work-package (r) - Min value: MinWorkPackageResultsSize. Max value: MaxWorkPackageResultsSize.
}

type WorkPackageSpecification struct {
WorkPackageHash crypto.Hash // Hash of the work-package (h)
AuditableWorkBundleLength uint32 // Length of the auditable work bundle (l)
ErasureRoot crypto.Hash // Erasure root (u) - is the root of a binary Merkle tree which functions as a commitment to all data required for the auditing of the report and for use by later workpackages should they need to retrieve any data yielded. It is thus used by assurers to verify the correctness of data they have been sent by guarantors, and it is later verified as correct by auditors.
SegmentRoot crypto.Hash // Segment root (e) - root of a constant-depth, left-biased and zero-hash-padded binary Merkle tree committing to the hashes of each of the exported segments of each work-item. These are used by guarantors to verify the correctness of any reconstructed segments they are called upon to import for evaluation of some later work-package.
SegmentCount uint16 // Segment count (n)
}

// RefinementContext describes the context of the chain at the point that the report’s corresponding work-package was evaluated.
type RefinementContext struct {
Anchor RefinementContextAnchor // Historical block anchor
LookupAnchor RefinementContextLookupAnchor // Historical block anchor
PrerequisiteWorkPackage *crypto.Hash // Prerequisite work package (p) (optional)
PrerequisiteWorkPackage []crypto.Hash // Prerequisite work package (p) (optional)
}

type RefinementContextAnchor struct {
Expand Down
6 changes: 4 additions & 2 deletions internal/block/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/ed25519"
"errors"
"fmt"

"github.com/eigerco/strawberry/pkg/db"
"github.com/eigerco/strawberry/pkg/db/pebble"

Expand All @@ -30,8 +31,9 @@ type Header struct {
// EpochMarker consists of epoch randomness and a sequence of
// Bandersnatch keys defining the Bandersnatch validator keys (kb) beginning in the next epoch.
type EpochMarker struct {
Entropy crypto.Hash
Keys [common.NumberOfValidators]crypto.BandersnatchPublicKey
Entropy crypto.Hash
TicketsEntropy crypto.Hash
Keys [common.NumberOfValidators]crypto.BandersnatchPublicKey
}

type WinningTicketMarker [jamtime.TimeslotsPerEpoch]Ticket
Expand Down
5 changes: 3 additions & 2 deletions internal/state/block_seal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package state
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/eigerco/strawberry/internal/block"
"github.com/eigerco/strawberry/internal/crypto"
"github.com/eigerco/strawberry/internal/safrole"
"github.com/eigerco/strawberry/internal/testutils"
"github.com/eigerco/strawberry/internal/validator"
"github.com/eigerco/strawberry/pkg/serialization/codec/jam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestEncodeUnsealedHeader(t *testing.T) {
Expand Down
24 changes: 14 additions & 10 deletions internal/state/merkle/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/eigerco/strawberry/internal/state"
"testing"

"github.com/eigerco/strawberry/internal/state"

"github.com/stretchr/testify/require"

"github.com/eigerco/strawberry/internal/block"
"github.com/eigerco/strawberry/internal/common"
"github.com/eigerco/strawberry/internal/crypto"
Expand All @@ -16,7 +19,6 @@ import (
"github.com/eigerco/strawberry/internal/testutils"
"github.com/eigerco/strawberry/internal/validator"
"github.com/eigerco/strawberry/pkg/serialization/codec/jam"
"github.com/stretchr/testify/require"
)

func RandomValidatorsData(t *testing.T) safrole.ValidatorsData {
Expand Down Expand Up @@ -117,10 +119,11 @@ func RandomCoreAssignments(t *testing.T) state.CoreAssignments {
LookupAnchor: block.RefinementContextLookupAnchor{HeaderHash: testutils.RandomHash(t), Timeslot: testutils.RandomTimeslot()},
PrerequisiteWorkPackage: nil,
},
CoreIndex: uint16(i),
AuthorizerHash: testutils.RandomHash(t),
Output: []byte("output"),
WorkResults: []block.WorkResult{RandomWorkResult(t)},
CoreIndex: uint16(i),
AuthorizerHash: testutils.RandomHash(t),
Output: []byte("output"),
SegmentRootLookup: make(map[crypto.Hash]crypto.Hash),
WorkResults: []block.WorkResult{RandomWorkResult(t)},
},
Time: testutils.RandomTimeslot(),
}
Expand Down Expand Up @@ -183,10 +186,11 @@ func RandomWorkReport(t *testing.T) block.WorkReport {
Timeslot: testutils.RandomTimeslot(),
},
},
CoreIndex: testutils.RandomUint16(),
AuthorizerHash: testutils.RandomHash(t),
Output: []byte("random output"),
WorkResults: []block.WorkResult{RandomWorkResult(t)},
CoreIndex: testutils.RandomUint16(),
AuthorizerHash: testutils.RandomHash(t),
Output: []byte("random output"),
SegmentRootLookup: make(map[crypto.Hash]crypto.Hash),
WorkResults: []block.WorkResult{RandomWorkResult(t)},
}
}

Expand Down
8 changes: 5 additions & 3 deletions internal/state/merkle/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package state

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/eigerco/strawberry/internal/crypto"
"github.com/eigerco/strawberry/internal/safrole"
"github.com/eigerco/strawberry/pkg/serialization/codec/jam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"testing"
)

func TestSerializeState(t *testing.T) {
Expand Down
Loading

0 comments on commit 4980c42

Please sign in to comment.