Skip to content

Commit

Permalink
Merge pull request #479 from iotaledger/feat/genesis-slot
Browse files Browse the repository at this point in the history
Add support for GenesisSlot protocol parameters to have a genesis != 0
  • Loading branch information
karimodm authored Nov 8, 2023
2 parents 9094100 + b027254 commit 2c36831
Show file tree
Hide file tree
Showing 40 changed files with 227 additions and 155 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20231108050255-98e0fa35e936
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231108050255-98e0fa35e936
github.com/iotaledger/hive.go/stringify v0.0.0-20231108050255-98e0fa35e936
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac
github.com/iotaledger/iota.go/v4 v4.0.0-20231108050608-afce96cfe8a6
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231108104504-1445f545de82
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231108104322-f301c3573998
github.com/iotaledger/iota.go/v4 v4.0.0-20231108103955-bf75d703d8aa
github.com/labstack/echo/v4 v4.11.2
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.32.0
Expand All @@ -42,6 +42,7 @@ require (
go.uber.org/atomic v1.11.0
go.uber.org/dig v1.17.1
golang.org/x/crypto v0.14.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
)
Expand Down Expand Up @@ -168,7 +169,6 @@ require (
go.uber.org/mock v0.3.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/image v0.13.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231108050255-98e0fa3
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231108050255-98e0fa35e936/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8=
github.com/iotaledger/hive.go/stringify v0.0.0-20231108050255-98e0fa35e936 h1:Y4HgL5gm9S27usg5M2t6wi1BSdCxVorM62lwnpKuMd4=
github.com/iotaledger/hive.go/stringify v0.0.0-20231108050255-98e0fa35e936/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5 h1:17JDzMKTMXKF3xys6gPURRddkZhg1LY+xwfhbr/sVqg=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5/go.mod h1:LsJvoBUVVnY7tkwwByCVtAwmp5bFXdyJNGU/+KVQJVM=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac h1:c7R33+TQGMYP6pvLUQQaqpdDFl+GZbhAcfGMI0285fo=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac/go.mod h1:qPuMUvCTaghsnYRDnRoRuztTyEKFlmi2S7gb44rH7WM=
github.com/iotaledger/iota.go/v4 v4.0.0-20231108050608-afce96cfe8a6 h1:4kvG+BB4GOBsNYPY/enPo3xeC65A133L9cD73Kf1p9Q=
github.com/iotaledger/iota.go/v4 v4.0.0-20231108050608-afce96cfe8a6/go.mod h1:8iDORW4/e4NztyAGqjW07uSMjbhs7snbxw+81IWOczY=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231108104504-1445f545de82 h1:FdM1lxUKgENO3oOlF5blVqmjER44mLIHGpavyUOY5JI=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231108104504-1445f545de82/go.mod h1:HVxkGPraMDTRudfG9AFN7Ga9gijp6skXB9TKNBc4KgI=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231108104322-f301c3573998 h1:KkC0SaWrjSMg897r2DDosJYALFfLadFST3Fvoaxg7hw=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231108104322-f301c3573998/go.mod h1:c+lBG3vgt2rgXHeOncK8hMllMwihTAtVbu790NslW2w=
github.com/iotaledger/iota.go/v4 v4.0.0-20231108103955-bf75d703d8aa h1:A2nadmSbmn62f6wtrqvv/TCCF2sDiiwyDnl6brbRo1E=
github.com/iotaledger/iota.go/v4 v4.0.0-20231108103955-bf75d703d8aa/go.mod h1:8iDORW4/e4NztyAGqjW07uSMjbhs7snbxw+81IWOczY=
github.com/ipfs/boxo v0.13.1 h1:nQ5oQzcMZR3oL41REJDcTbrvDvuZh3J9ckc9+ILeRQI=
github.com/ipfs/boxo v0.13.1/go.mod h1:btrtHy0lmO1ODMECbbEY1pxNtrLilvKSYLoGQt1yYCk=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
2 changes: 1 addition & 1 deletion pkg/model/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Commitment struct {
}

func NewEmptyCommitment(api iotago.API) *Commitment {
emptyCommitment := iotago.NewEmptyCommitment(api.ProtocolParameters().Version())
emptyCommitment := iotago.NewEmptyCommitment(api)
emptyCommitment.ReferenceManaCost = api.ProtocolParameters().CongestionControlParameters().MinReferenceManaCost

return lo.PanicOnErr(CommitmentFromCommitment(emptyCommitment, api))
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/engine/committed_slot_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *CommittedSlotAPI) Roots() (committedRoots *iotago.Roots, err error) {
return nil, ierrors.Errorf("no roots storage for slot %d", c.CommitmentID)
}

roots, err := rootsStorage.Load(c.CommitmentID)
roots, _, err := rootsStorage.Load(c.CommitmentID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to load roots for slot %d", c.CommitmentID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func NewTestFramework(test *testing.T) *TestFramework {
iotago.CommitmentID.Bytes,
iotago.CommitmentIDFromBytes,
), nil
}, func() iotago.BlockID {
return tpkg.TestAPI.ProtocolParameters().GenesisBlockID()
})

t.blockCache = blocks.New(evictionState, api.SingleVersionProvider(tpkg.TestAPI))
Expand All @@ -63,7 +65,7 @@ func NewTestFramework(test *testing.T) *TestFramework {
t.Events = instance.Events()
t.Instance = instance

genesisBlock := blocks.NewRootBlock(iotago.EmptyBlockID, iotago.NewEmptyCommitment(tpkg.TestAPI.Version()).MustID(), time.Unix(tpkg.TestAPI.TimeProvider().GenesisUnixTime(), 0))
genesisBlock := blocks.NewRootBlock(tpkg.TestAPI.ProtocolParameters().GenesisBlockID(), iotago.NewEmptyCommitment(tpkg.TestAPI).MustID(), time.Unix(tpkg.TestAPI.TimeProvider().GenesisUnixTime(), 0))
t.blocks.Set("Genesis", genesisBlock)
genesisBlock.ID().RegisterAlias("Genesis")
evictionState.AddRootBlock(genesisBlock.ID(), genesisBlock.SlotCommitmentID())
Expand Down
14 changes: 8 additions & 6 deletions pkg/protocol/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func New(
&Engine{
Events: NewEvents(),
Storage: storageInstance,
EvictionState: eviction.NewState(storageInstance.LatestNonEmptySlot(), storageInstance.RootBlocks),
EvictionState: eviction.NewState(storageInstance.LatestNonEmptySlot(), storageInstance.RootBlocks, storageInstance.GenesisRootBlockID),
Workers: workers,
errorHandler: errorHandler,

Expand Down Expand Up @@ -183,7 +183,7 @@ func New(
}

// Only mark any pruning indexes if we loaded a non-genesis snapshot
if e.Storage.Settings().LatestFinalizedSlot() > 0 {
if e.Storage.Settings().LatestFinalizedSlot() > e.Storage.GenesisRootBlockID().Slot() {
if _, _, err := e.Storage.PruneByDepth(1); err != nil {
if !ierrors.Is(err, database.ErrNoPruningNeeded) &&
!ierrors.Is(err, database.ErrEpochPruned) {
Expand All @@ -199,7 +199,6 @@ func New(
} else {
// Restore from Disk
e.Storage.RestoreFromDisk()
e.EvictionState.PopulateFromStorage(e.Storage.Settings().LatestCommitment().Slot())

if err := e.Attestations.RestoreFromDisk(); err != nil {
panic(ierrors.Wrap(err, "failed to restore attestations from disk"))
Expand Down Expand Up @@ -488,11 +487,14 @@ func (e *Engine) setupPruning() {
// chain beyond a window based on eviction, which in turn is based on acceptance. In case of a partition, this behavior is
// clearly not desired.
func (e *Engine) EarliestRootCommitment(lastFinalizedSlot iotago.SlotIndex) (earliestCommitment *model.Commitment) {
maxCommittableAge := e.APIForSlot(lastFinalizedSlot).ProtocolParameters().MaxCommittableAge()
api := e.APIForSlot(lastFinalizedSlot)

genesisSlot := api.ProtocolParameters().GenesisSlot()
maxCommittableAge := api.ProtocolParameters().MaxCommittableAge()

var earliestRootCommitmentSlot iotago.SlotIndex
if lastFinalizedSlot <= maxCommittableAge {
earliestRootCommitmentSlot = 0
if lastFinalizedSlot <= genesisSlot+maxCommittableAge {
earliestRootCommitmentSlot = genesisSlot
} else {
earliestRootCommitmentSlot = lastFinalizedSlot - maxCommittableAge
}
Expand Down
Loading

0 comments on commit 2c36831

Please sign in to comment.