Skip to content

Commit

Permalink
Add service state transition (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
bamzedev authored Nov 7, 2024
1 parent 69bead3 commit 9d10f35
Show file tree
Hide file tree
Showing 4 changed files with 398 additions and 13 deletions.
6 changes: 6 additions & 0 deletions internal/block/assurance.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ type Assurance struct {
}

type AssurancesExtrinsic []Assurance

func HasAssuranceForCore(a Assurance, coreIndex uint16) bool {
byteIndex := coreIndex / 8
bitIndex := coreIndex % 8
return (a.Bitfield[byteIndex] & (1 << bitIndex)) != 0
}
2 changes: 2 additions & 0 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const (
AdditionalMinimumBalancePerItem = 10 // (BI) The additional minimum balance required per item of elective service state.
AdditionalMinimumBalancePerOctet = 1 // (BL) The additional minimum balance required per octet of elective service state.
TransferMemoSizeBytes = 128 // (M) Size of the transfer memo in bytes.
// TODO: This isn't defined in the GP as a const. Can't find the value.
MaximumAccumulationGas = 50000 // (GA) Maximum total gas that can be consumed by accumulation operations.
)


Expand Down
22 changes: 21 additions & 1 deletion internal/state/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package state

import (
"crypto/ed25519"

"github.com/eigerco/strawberry/internal/block"
"github.com/eigerco/strawberry/internal/common"
"github.com/eigerco/strawberry/internal/crypto"
"github.com/eigerco/strawberry/internal/jamtime"
"github.com/eigerco/strawberry/internal/safrole"
"github.com/eigerco/strawberry/internal/service"
)

type Assignment struct {
Expand Down Expand Up @@ -44,9 +47,26 @@ type AccumulationOperand struct {
AuthorizationOutput []byte // Authorization output (a ∈ Y)
}

// AccumulationResult represents the result type from equation 162:
// A: NS → {s ∈ A?, v ∈ ⟦K⟧V, t ∈ ⟦T⟧, r ∈ H?, c ∈ C⟦H⟧QHC, n ∈ D⟨NS → A⟩, p ∈ {m,a,v ∈ NS, g ∈ D⟨NS → NG⟩}}
type AccumulationResult struct {
ServiceState *service.ServiceAccount // s - Optional updated service account state
ValidatorUpdates safrole.ValidatorsData // v - Single validator data set, not a slice
DeferredTransfers []service.DeferredTransfer // t - Deferred transfers sequence
AccumulationRoot *crypto.Hash // r - Optional accumulation result hash
CoreAssignments PendingAuthorizersQueues // c - Core authorizations queue
NewServices service.ServiceState // n - Newly created services mapping
PrivilegedUpdates struct { // p - Privileged service updates
ManagerServiceId block.ServiceId // m - Manager service
AssignServiceId block.ServiceId // a - Assign service
DesignateServiceId block.ServiceId // v - Designate service
GasAssignments map[block.ServiceId]uint64 // g - Gas assignments
}
}

// Context is an intermediate value for state transition calculations
// TODO: Add relevant fields when state transitions are implemented
type Context struct {
// Add relevant fields
Accumulations map[uint32]crypto.Hash
Accumulations map[block.ServiceId]crypto.Hash
}
Loading

0 comments on commit 9d10f35

Please sign in to comment.