Skip to content

Commit

Permalink
Add tiny reporting vectors and all tests passing except 4 skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-romano committed Dec 30, 2024
1 parent d3e3cbd commit c474276
Show file tree
Hide file tree
Showing 45 changed files with 20,857 additions and 175 deletions.
1 change: 1 addition & 0 deletions internal/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ const (
SizeOfSegment = 4104 // WG = WP*WE = 4104: The size of a segment in octets.
MaxWorkPackageSize = 12 * 1 << 20 // WB = 12 MB: The maximum size of an encoded work-package in octets (including extrinsic data and import implications).
MaxAllocatedGasAccumulation = 100_000 // GA = 100,000: The gas allocated to invoke a work-report’s Accumulation logic.
WorkReportMaxSumOfDependencies = 8 // (J) The maximum sum of dependency items in a work-report.
)
3 changes: 2 additions & 1 deletion internal/common/constants_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ const (
TotalNumberOfCores uint16 = 2
ValidatorsSuperMajority = (2 * NumberOfValidators / 3) + 1
WorkReportTimeoutPeriod = jamtime.Timeslot(5)
ValidatorRotationPeriod = jamtime.Timeslot(10)
ValidatorRotationPeriod = jamtime.Timeslot(4)
MaxTicketExtrinsicSize = 16
MaxHistoricalTimeslotsForPreimageMeta = 3
SizeOfSegment = 4104
MaxWorkPackageSize = 12 * 1 << 20 // 12 MB: The maximum size of an encoded work-package in octets (including extrinsic data and import implications).
MaxAllocatedGasAccumulation = 100_000
WorkReportMaxSumOfDependencies = 8
)
2 changes: 1 addition & 1 deletion internal/jamtime/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const (

// TimeslotsPerEpoch defines the number of timeslots in each epoch.
// In the JAM protocol, each epoch consists of exactly 600 timeslots,
// as specified in the JAM Graypaper.
// as specified in the JAM Graypaper. (E)
TimeslotsPerEpoch = 600

// EpochDuration defines the total duration of each epoch.
Expand Down
8 changes: 8 additions & 0 deletions internal/statetransition/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package statetransition

import "github.com/pkg/errors"

var (
ErrTimeslotOutOfRange = errors.New("timeslot out of range")
ErrCredentialVerificationFailed = errors.New("credential verification failed")
)
474 changes: 327 additions & 147 deletions internal/statetransition/state_transition.go

Large diffs are not rendered by default.

50 changes: 26 additions & 24 deletions internal/statetransition/state_transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"github.com/stretchr/testify/require"
)

func TestCalculateNewTimeStateTransiton(t *testing.T) {
func TestCalculateNewTimeStateTransition(t *testing.T) {
header := block.Header{
TimeSlotIndex: 2,
}
newTimeState := calculateNewTimeState(header)
newTimeState := CalculateNewTimeState(header)
require.Equal(t, newTimeState, header.TimeSlotIndex)
}

Expand Down Expand Up @@ -179,7 +179,7 @@ func TestCalculateIntermediateServiceState(t *testing.T) {
},
}

newServiceState := calculateIntermediateServiceState(preimages, serviceState, serviceState, newTimeslot)
newServiceState := CalculateIntermediateServiceState(preimages, serviceState, newTimeslot)
require.Equal(t, expectedServiceState, newServiceState)
}

Expand All @@ -197,7 +197,7 @@ func TestCalculateIntermediateServiceStateEmptyPreimages(t *testing.T) {

expectedServiceState := serviceState

newServiceState := calculateIntermediateServiceState(block.PreimageExtrinsic{}, serviceState, serviceState, jamtime.Timeslot(100))
newServiceState := CalculateIntermediateServiceState(block.PreimageExtrinsic{}, serviceState, jamtime.Timeslot(100))
require.Equal(t, expectedServiceState, newServiceState)
}

Expand Down Expand Up @@ -225,7 +225,7 @@ func TestCalculateIntermediateServiceStateNonExistentService(t *testing.T) {

expectedServiceState := serviceState

newServiceState := calculateIntermediateServiceState(preimages, serviceState, serviceState, newTimeslot)
newServiceState := CalculateIntermediateServiceState(preimages, serviceState, newTimeslot)
require.Equal(t, expectedServiceState, newServiceState)
}

Expand Down Expand Up @@ -269,7 +269,7 @@ func TestCalculateIntermediateServiceStateMultiplePreimages(t *testing.T) {
},
}

newServiceState := calculateIntermediateServiceState(preimages, serviceState, serviceState, newTimeslot)
newServiceState := CalculateIntermediateServiceState(preimages, serviceState, newTimeslot)
require.Equal(t, expectedServiceState, newServiceState)
}

Expand Down Expand Up @@ -314,7 +314,7 @@ func TestCalculateIntermediateServiceStateExistingPreimage(t *testing.T) {
},
}

newServiceState := calculateIntermediateServiceState(preimages, serviceState, serviceState, newTimeslot)
newServiceState := CalculateIntermediateServiceState(preimages, serviceState, newTimeslot)
require.Equal(t, expectedServiceState, newServiceState)
}

Expand All @@ -341,7 +341,7 @@ func TestCalculateIntermediateServiceStateExistingMetadata(t *testing.T) {

expectedServiceState := serviceState // Should remain unchanged

newServiceState := calculateIntermediateServiceState(preimages, serviceState, serviceState, newTimeslot)
newServiceState := CalculateIntermediateServiceState(preimages, serviceState, newTimeslot)
require.Equal(t, expectedServiceState, newServiceState)
}

Expand Down Expand Up @@ -370,7 +370,7 @@ func TestCalculateIntermediateCoreAssignmentsFromExtrinsics(t *testing.T) {
{WorkReport: workReport2},
}

newAssignments := calculateIntermediateCoreAssignmentsFromExtrinsics(disputes, coreAssignments)
newAssignments := CalculateIntermediateCoreAssignmentsFromExtrinsics(disputes, coreAssignments)
require.Equal(t, expectedAssignments, newAssignments)
}

Expand All @@ -394,7 +394,7 @@ func TestCalculateIntermediateCoreAssignmentsFromAvailability(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
assurances := createAssuranceExtrinsic(tc.availableCores, tc.validators)
initialAssignments := createInitialAssignments()
newAssignments, err := calculateIntermediateCoreAssignmentsFromAvailability(assurances, initialAssignments, block.Header{TimeSlotIndex: jamtime.Timeslot(12)})
newAssignments, err := CalculateIntermediateCoreAssignmentsFromAvailability(assurances, initialAssignments, block.Header{TimeSlotIndex: jamtime.Timeslot(12)})
require.NoError(t, err)

removedCount := uint16(0)
Expand Down Expand Up @@ -484,16 +484,18 @@ func TestCalculateNewCoreAssignments(t *testing.T) {

intermediateAssignments := state.CoreAssignments{}

newAssignments, _ := calculateNewCoreAssignments(
newAssignments, _, err := CalculateNewCoreAssignments(
guarantees,
intermediateAssignments,
validatorState,
currentTimeslot,
entropyPool,
)

// Assert
require.Nil(t, newAssignments[selectedCoreIndex])
require.NoError(t, err)
require.Equal(t, workReport, *newAssignments[selectedCoreIndex].WorkReport)
require.Equal(t, currentTimeslot, newAssignments[selectedCoreIndex].Time)

})

t.Run("invalid guarantee due to timeslot too old", func(t *testing.T) {
Expand Down Expand Up @@ -551,14 +553,14 @@ func TestCalculateNewCoreAssignments(t *testing.T) {

intermediateAssignments := state.CoreAssignments{}

newAssignments, _ := calculateNewCoreAssignments(
newAssignments, _, err := CalculateNewCoreAssignments(
guarantees,
intermediateAssignments,
validatorState,
currentTimeslot,
state.EntropyPool{},
)

require.ErrorIs(t, err, ErrTimeslotOutOfRange)
require.Nil(t, newAssignments[0])
})

Expand Down Expand Up @@ -616,14 +618,14 @@ func TestCalculateNewCoreAssignments(t *testing.T) {

intermediateAssignments := state.CoreAssignments{}

newAssignments, _ := calculateNewCoreAssignments(
newAssignments, _, err := CalculateNewCoreAssignments(
guarantees,
intermediateAssignments,
validatorState,
currentTimeslot,
state.EntropyPool{},
)

require.ErrorIs(t, err, ErrCredentialVerificationFailed)
require.Nil(t, newAssignments[0])
})

Expand Down Expand Up @@ -683,14 +685,14 @@ func TestCalculateNewCoreAssignments(t *testing.T) {

intermediateAssignments := state.CoreAssignments{}

newAssignments, _ := calculateNewCoreAssignments(
newAssignments, _, err := CalculateNewCoreAssignments(
guarantees,
intermediateAssignments,
validatorState,
currentTimeslot,
state.EntropyPool{},
)

assert.ErrorIs(t, err, ErrCredentialVerificationFailed)
require.Nil(t, newAssignments[0])
})
}
Expand All @@ -707,7 +709,7 @@ func TestCalculateNewCoreAuthorizations(t *testing.T) {
newAuth := testutils.RandomHash(t)
pendingAuths[0][1] = newAuth // At index 1 (matching TimeSlotIndex)

newAuths := calculateNewCoreAuthorizations(header, block.GuaranteesExtrinsic{}, pendingAuths, currentAuths)
newAuths := CalculateNewCoreAuthorizations(header, block.GuaranteesExtrinsic{}, pendingAuths, currentAuths)

require.Len(t, newAuths[0], 1)
assert.Equal(t, newAuth, newAuths[0][0])
Expand Down Expand Up @@ -739,7 +741,7 @@ func TestCalculateNewCoreAuthorizations(t *testing.T) {
newAuth := testutils.RandomHash(t)
pendingAuths[0][1] = newAuth // At index 1 (matching TimeSlotIndex)

newAuths := calculateNewCoreAuthorizations(header, guarantees, pendingAuths, currentAuths)
newAuths := CalculateNewCoreAuthorizations(header, guarantees, pendingAuths, currentAuths)

require.Len(t, newAuths[0], 1)
assert.Equal(t, newAuth, newAuths[0][0])
Expand All @@ -762,7 +764,7 @@ func TestCalculateNewCoreAuthorizations(t *testing.T) {
newAuth := testutils.RandomHash(t)
pendingAuths[0][1] = newAuth

newAuths := calculateNewCoreAuthorizations(header, block.GuaranteesExtrinsic{}, pendingAuths, currentAuths)
newAuths := CalculateNewCoreAuthorizations(header, block.GuaranteesExtrinsic{}, pendingAuths, currentAuths)

// Check that size limit is maintained and oldest auth was removed
require.Len(t, newAuths[0], state.MaxAuthorizersPerCore)
Expand All @@ -782,7 +784,7 @@ func TestCalculateNewCoreAuthorizations(t *testing.T) {
// Empty pending authorizations
pendingAuths := state.PendingAuthorizersQueues{}

newAuths := calculateNewCoreAuthorizations(header, block.GuaranteesExtrinsic{}, pendingAuths, currentAuths)
newAuths := CalculateNewCoreAuthorizations(header, block.GuaranteesExtrinsic{}, pendingAuths, currentAuths)

// Should keep existing authorizations unchanged
require.Len(t, newAuths[0], 1)
Expand All @@ -808,7 +810,7 @@ func TestCalculateNewCoreAuthorizations(t *testing.T) {
pendingAuths[0][1] = newAuth0
pendingAuths[1][1] = newAuth1

newAuths := calculateNewCoreAuthorizations(header, block.GuaranteesExtrinsic{}, pendingAuths, currentAuths)
newAuths := CalculateNewCoreAuthorizations(header, block.GuaranteesExtrinsic{}, pendingAuths, currentAuths)

require.Len(t, newAuths[0], 2)
require.Len(t, newAuths[1], 2)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/disputes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ type SegmentRootPair struct {
}

type Rho struct {
Report *Report `json:"report"`
Timeout int `json:"timeout"`
Report *Report `json:"Report"`
Timeout int `json:"Timeout"`
}

type ValidatorKey struct {
Expand Down
Loading

0 comments on commit c474276

Please sign in to comment.