Skip to content

Commit

Permalink
Merge pull request #627 from iotaledger/fix/rootblock-all-accepted
Browse files Browse the repository at this point in the history
Make RootBlocks objective
  • Loading branch information
karimodm authored Dec 12, 2023
2 parents 568c35c + a69e15f commit f421d40
Show file tree
Hide file tree
Showing 27 changed files with 280 additions and 335 deletions.
7 changes: 5 additions & 2 deletions components/inx/server_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import (
)

func (s *Server) ReadActiveRootBlocks(_ context.Context, _ *inx.NoParams) (*inx.RootBlocksResponse, error) {
activeRootBlocks := deps.Protocol.Engines.Main.Get().EvictionState.ActiveRootBlocks()
latestRootBlockID, latestRootBlockSlotCommitmentID := deps.Protocol.Engines.Main.Get().EvictionState.LatestActiveRootBlock()

return inx.WrapRootBlocks(activeRootBlocks), nil
// TODO: we should maybe change the INX API to return only the latest rootblock instead of the whole active set.
return inx.WrapRootBlocks(map[iotago.BlockID]iotago.CommitmentID{
latestRootBlockID: latestRootBlockSlotCommitmentID,
}), nil
}

func (s *Server) ReadBlock(_ context.Context, blockID *inx.BlockId) (*inx.RawBlock, error) {
Expand Down
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ require (
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39
github.com/iotaledger/hive.go/app v0.0.0-20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/constraints v0.0.0-20231207181026-f482ac139305
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/crypto v0.0.0-20231207181026-f482ac139305
github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/ierrors v0.0.0-20231207181026-f482ac139305
github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39
github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/lo v0.0.0-20231207181026-f482ac139305
github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c
github.com/iotaledger/hive.go/logger v0.0.0-20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/runtime v0.0.0-20231207181026-f482ac139305
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad
github.com/iotaledger/hive.go/stringify v0.0.0-20231207181026-f482ac139305
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231206124511-b78dc962031f
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231206124145-f773dfe3927e
github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5
github.com/iotaledger/iota.go/v4 v4.0.0-20231211160706-492c65d5e3f5
github.com/labstack/echo/v4 v4.11.3
github.com/labstack/gommon v0.4.1
github.com/libp2p/go-libp2p v0.32.0
Expand All @@ -42,7 +42,6 @@ require (
go.uber.org/atomic v1.11.0
go.uber.org/dig v1.17.1
golang.org/x/crypto v0.16.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 @@ -89,6 +88,7 @@ require (
github.com/huin/goupnp v1.3.0 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00 // indirect
github.com/ipfs/boxo v0.13.1 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down Expand Up @@ -160,7 +160,6 @@ require (
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/wollac/iota-crypto-demo v0.0.0-20221117162917-b10619eccb98 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
Expand All @@ -169,6 +168,7 @@ 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.19.0 // indirect
Expand Down
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -279,36 +279,38 @@ github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39 h1:jxoBAPgC
github.com/iotaledger/hive.go/ads v0.0.0-20231205131244-472357435a39/go.mod h1:gbUvr01B5ha530GnNm8K2OsHXOd2BtzBYOMxyTX3iDg=
github.com/iotaledger/hive.go/app v0.0.0-20231206114953-6a65a82e30ad h1:v7dkbVLSsmzgOWT2vjvv1MdKQXvqFbvIkx8mvh6VK7g=
github.com/iotaledger/hive.go/app v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:hTHKGFbZnuiW8yEgDuuL7ZjQTCnl8bXyHLmj3LPa648=
github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad h1:4XL7IIvdsWHxSKQfU+sgq3H9egN54053LF9TwMfDcTg=
github.com/iotaledger/hive.go/constraints v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/constraints v0.0.0-20231207181026-f482ac139305 h1:ar+IWfqO7B1M5+kuKGUJnfg0i/YuuM1oN5i8byp/F7A=
github.com/iotaledger/hive.go/constraints v0.0.0-20231207181026-f482ac139305/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad h1:iNzb/Oy/nucIOXOzRcwSqqFsaeKwr2JZpZYSLp8xjlE=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231206114953-6a65a82e30ad/go.mod h1:CO28KMA6Pp5LJPiigPQQ276zQofES+jMod08U5pyRFA=
github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad h1:pUL2UZbF4S8FIV7uKo9p+IGfZ658K1VNorQ6rzDMRvs=
github.com/iotaledger/hive.go/crypto v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:7vHoF//1Pt3nu0l8nDIw7bEgv2GfbL3kSgjp7Rdqhd4=
github.com/iotaledger/hive.go/crypto v0.0.0-20231207181026-f482ac139305 h1:OR2TClxTtst906F4tok9xzhBTKO81qrUFdxIAoaZVvE=
github.com/iotaledger/hive.go/crypto v0.0.0-20231207181026-f482ac139305/go.mod h1:7vHoF//1Pt3nu0l8nDIw7bEgv2GfbL3kSgjp7Rdqhd4=
github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad h1:adLrD6dOEkM5Xdg6AOPt9/HYqy/pQ5FrprDpW4/VqUU=
github.com/iotaledger/hive.go/ds v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:NmZRIoxtL6iQdVK6n5W+JOx58K/0Yn8k7WuSvpKPQ+M=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad h1:WDl58zJKHfwbzHs+ZB8Jq3YNgVQE5Neu2NeaX3FZuyU=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231207181026-f482ac139305 h1:v7/zMhNcr6hibXFZXZ4xV/S27ESUytQFgUQ1oo10iic=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231207181026-f482ac139305/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39 h1:Gp2h+Els9cTVYYnYsHX3zLuixb0XggIj2okK570aKww=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231205131244-472357435a39/go.mod h1:ytfKoHr/nF8u0y0G4mamfG0yjFtJiJVk0kgjnPOtsSY=
github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad h1:qpCsjw+InLL824QPu3lY/osck4DhucBKhCs5/E8OH+A=
github.com/iotaledger/hive.go/lo v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:ETXGXymFyNcUq2t4I9e7ZK18f9bxUWYat4pjZ9W0rWc=
github.com/iotaledger/hive.go/lo v0.0.0-20231207181026-f482ac139305 h1:zxVbTEWutMvZhS0VLu/OmBk2WpMjrXQ7l67VBwsExtc=
github.com/iotaledger/hive.go/lo v0.0.0-20231207181026-f482ac139305/go.mod h1:ETXGXymFyNcUq2t4I9e7ZK18f9bxUWYat4pjZ9W0rWc=
github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c h1:Ksts6VjPj9y0o2Nis+2tHtDGWITNJ4yju87ZlHLPuOo=
github.com/iotaledger/hive.go/log v0.0.0-20231206113509-4b4ff95ac61c/go.mod h1:Td3R6QmYw0svZI1GuZ/tN9s0VNaHassXSKLCc70aX9w=
github.com/iotaledger/hive.go/logger v0.0.0-20231206114953-6a65a82e30ad h1:fazCxogqOLDEPNDPWYDLTDpYmwgTJgIaC2Z6VN52S4M=
github.com/iotaledger/hive.go/logger v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:hVaVODS+Uik0obf3SVEHFQNruUko/uqIgD/GKwhn49M=
github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad h1:HpupWK8iqFt+Sdogkh2/N8ojalmevYy+FzhjOuy7Y7E=
github.com/iotaledger/hive.go/runtime v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:Z9NFsByMh1Kf98f3v3ifeZRycbS2db1hjswTQG1MxnE=
github.com/iotaledger/hive.go/runtime v0.0.0-20231207181026-f482ac139305 h1:7CW1/EbG+RvkjbyOf6JA1u1feax/cpex/6a8CLbaA4I=
github.com/iotaledger/hive.go/runtime v0.0.0-20231207181026-f482ac139305/go.mod h1:Z9NFsByMh1Kf98f3v3ifeZRycbS2db1hjswTQG1MxnE=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad h1:c8uwbBZDqpiCNN9/9Jji7Z4lL0GdVnORp8WMouiuknk=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231206114953-6a65a82e30ad/go.mod h1:FoH3T6yKlZJp8xm8K+zsQiibSynp32v21CpWx8xkek8=
github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad h1:VC3OgdSbyngY7/gxVj66fKd/nGmN6P0/myr348nx7vA=
github.com/iotaledger/hive.go/stringify v0.0.0-20231206114953-6a65a82e30ad/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/hive.go/stringify v0.0.0-20231207181026-f482ac139305 h1:KjbaklWvZb4zIcXBETHzl6XFTAf8wtAlFDfaF0Z1Daw=
github.com/iotaledger/hive.go/stringify v0.0.0-20231207181026-f482ac139305/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231206124511-b78dc962031f h1:V68Ijq1A64gB9r0Rhc4ybLGH66rXqZ2Ly0L4uuaLrMg=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231206124511-b78dc962031f/go.mod h1:Dy3Gv4Dn1zufB177x6IXETP3zTeiWQ1+HMVQR0Bt/ew=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231206124145-f773dfe3927e h1:jbtiUlmTpTdGiRBW1pniPSqRcDMJaIW8fGS+uORryas=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231206124145-f773dfe3927e/go.mod h1:zEb9onVHnDUStl5SsFBj7H0HBKfIN0c/pUND8Llfqp8=
github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5 h1:0KgQFpVRnKd6CdCwXo3Kg/SL27xkeKh2SMoU5G1TkZk=
github.com/iotaledger/iota.go/v4 v4.0.0-20231206123921-2af411eef0b5/go.mod h1:tiswk1O1wSAi9GE6tD1j43+bLmWU9Je07aZLaJ0+Ha0=
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00 h1:j5udgLtSN6wQgFI9vnhkdJsqsVdJmwtoc0yOmT/Ila4=
github.com/iotaledger/iota-crypto-demo v0.0.0-20231208171603-786bb32fdb00/go.mod h1:gt+URx7DZu414nZME7jtGgxR4DVTSnNa1jF2trTUTZ0=
github.com/iotaledger/iota.go/v4 v4.0.0-20231211160706-492c65d5e3f5 h1:2iQUEuYvuyeYtZBr6bRoM4xFLxRiQ66aBPgKuJTirh0=
github.com/iotaledger/iota.go/v4 v4.0.0-20231211160706-492c65d5e3f5/go.mod h1:jU3Jlnhwv4KWlpft84lu9/M0QkCykESl29bL4oCenKs=
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 Expand Up @@ -658,8 +660,6 @@ github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0 h1:GDDkbFiaK8jsSD
github.com/warpfork/go-wish v0.0.0-20220906213052-39a1cc7a02d0/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 h1:EKhdznlJHPMoKr0XTrX+IlJs1LH3lyx2nfr1dOlZ79k=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
github.com/wollac/iota-crypto-demo v0.0.0-20221117162917-b10619eccb98 h1:i7k63xHOX2ntuHrhHewfKro67c834jug2DIk599fqAA=
github.com/wollac/iota-crypto-demo v0.0.0-20221117162917-b10619eccb98/go.mod h1:Knu2XMRWe8SkwTlHc/+ghP+O9DEaZRQQEyTjvLJ5Cck=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
Expand Down
1 change: 0 additions & 1 deletion pkg/model/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type Commitment struct {

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

return lo.PanicOnErr(CommitmentFromCommitment(emptyCommitment, api))
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/protocol/engine/blockdag/inmemoryblockdag/blockdag.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (b *BlockDAG) attach(data *model.Block) (block *blocks.Block, wasAttached b

// canAttach determines if the Block can be attached (does not exist and addresses a recent slot).
func (b *BlockDAG) shouldAttach(data *model.Block) (shouldAttach bool, err error) {
if b.evictionState.InRootBlockSlot(data.ID()) && !b.evictionState.IsRootBlock(data.ID()) {
if b.evictionState.InActiveRootBlockRange(data.ID()) && !b.evictionState.IsActiveRootBlock(data.ID()) {
b.retainBlockFailure(data.ID(), api.BlockFailureIsTooOld)
return false, ierrors.Errorf("block data with %s is too old (issued at: %s)", data.ID(), data.ProtocolBlock().Header.IssuingTime)
}
Expand All @@ -218,7 +218,7 @@ func (b *BlockDAG) shouldAttach(data *model.Block) (shouldAttach bool, err error
// this condition but exists as a missing entry, we mark it as invalid.
func (b *BlockDAG) canAttachToParents(modelBlock *model.Block) (parentsValid bool, err error) {
for _, parentID := range modelBlock.ProtocolBlock().Parents() {
if b.evictionState.InRootBlockSlot(parentID) && !b.evictionState.IsRootBlock(parentID) {
if b.evictionState.InActiveRootBlockRange(parentID) && !b.evictionState.IsActiveRootBlock(parentID) {
b.retainBlockFailure(modelBlock.ID(), api.BlockFailureParentIsTooOld)
return false, ierrors.Errorf("parent %s of block %s is too old", parentID, modelBlock.ID())
}
Expand All @@ -230,7 +230,7 @@ func (b *BlockDAG) canAttachToParents(modelBlock *model.Block) (parentsValid boo
// registerChild registers the given Block as a child of the parent. It triggers a BlockMissing event if the referenced
// Block does not exist, yet.
func (b *BlockDAG) registerChild(child *blocks.Block, parent iotago.Parent) {
if b.evictionState.IsRootBlock(parent.ID) {
if b.evictionState.IsActiveRootBlock(parent.ID) {
return
}

Expand Down
13 changes: 7 additions & 6 deletions pkg/protocol/engine/blocks/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ func (b *Blocks) Block(id iotago.BlockID) (block *Block, exists bool) {
b.evictionMutex.RLock()
defer b.evictionMutex.RUnlock()

if commitmentID, isRootBlock := b.evictionState.RootBlockCommitmentID(id); isRootBlock {
return NewRootBlock(id, commitmentID, b.apiProvider.APIForSlot(id.Slot()).TimeProvider().SlotEndTime(id.Slot())), true
if storage := b.blocks.Get(id.Slot()); storage != nil {
if block, exists = storage.Get(id); exists {
return block, true
}
}

storage := b.blocks.Get(id.Slot(), false)
if storage == nil {
return nil, false
if commitmentID, isRootBlock := b.evictionState.RootBlockCommitmentID(id); isRootBlock {
return NewRootBlock(id, commitmentID, b.apiProvider.APIForSlot(id.Slot()).TimeProvider().SlotEndTime(id.Slot())), true
}

return storage.Get(id)
return nil, false
}

func (b *Blocks) StoreOrUpdate(data *model.Block) (storedBlock *Block, evicted bool, updated bool) {
Expand Down
24 changes: 13 additions & 11 deletions pkg/protocol/engine/consensus/blockgadget/testframework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/iotaledger/hive.go/ds/shrinkingmap"
"github.com/iotaledger/hive.go/kvstore"
hivedb "github.com/iotaledger/hive.go/kvstore/database"
"github.com/iotaledger/hive.go/kvstore/mapdb"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/iota-core/pkg/core/account"
Expand All @@ -19,8 +20,10 @@ import (
"github.com/iotaledger/iota-core/pkg/protocol/engine/consensus/blockgadget/thresholdblockgadget"
"github.com/iotaledger/iota-core/pkg/protocol/engine/eviction"
"github.com/iotaledger/iota-core/pkg/protocol/sybilprotection/seatmanager/mock"
"github.com/iotaledger/iota-core/pkg/storage/database"
"github.com/iotaledger/iota-core/pkg/storage/permanent"
"github.com/iotaledger/iota-core/pkg/storage/prunable"
"github.com/iotaledger/iota-core/pkg/storage/prunable/epochstore"
"github.com/iotaledger/iota-core/pkg/storage/prunable/slotstore"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/builder"
"github.com/iotaledger/iota.go/v4/tpkg"
Expand All @@ -45,16 +48,15 @@ func NewTestFramework(test *testing.T) *TestFramework {
SeatManager: mock.NewManualPOA(iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), epochstore.NewStore(kvstore.Realm{}, mapdb.NewMapDB(), 0, (*account.Accounts).Bytes, account.AccountsFromBytes)),
}

evictionState := eviction.NewState(mapdb.NewMapDB(), func(slot iotago.SlotIndex) (*slotstore.Store[iotago.BlockID, iotago.CommitmentID], error) {
return slotstore.NewStore(slot, mapdb.NewMapDB(),
iotago.BlockID.Bytes,
iotago.BlockIDFromBytes,
iotago.CommitmentID.Bytes,
iotago.CommitmentIDFromBytes,
), nil
}, func() iotago.BlockID {
return tpkg.ZeroCostTestAPI.ProtocolParameters().GenesisBlockID()
})
prunableStorage := prunable.New(database.Config{
Engine: hivedb.EngineMapDB,
Directory: t.TempDir(),
}, iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI), func(err error) { panic(err) })

newSettings := permanent.NewSettings(mapdb.NewMapDB())
newSettings.StoreProtocolParametersForStartEpoch(tpkg.ZeroCostTestAPI.ProtocolParameters(), 0)

evictionState := eviction.NewState(newSettings, prunableStorage.RootBlocks)

t.blockCache = blocks.New(evictionState, iotago.SingleVersionProvider(tpkg.ZeroCostTestAPI))
instance := thresholdblockgadget.New(t.blockCache, t.SeatManager, func(err error) {
Expand Down
13 changes: 2 additions & 11 deletions pkg/protocol/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func New(
&Engine{
Events: NewEvents(),
Storage: storageInstance,
EvictionState: eviction.NewState(storageInstance.LatestNonEmptySlot(), storageInstance.RootBlocks, storageInstance.GenesisRootBlockID),
EvictionState: eviction.NewState(storageInstance.Settings(), storageInstance.RootBlocks),
RootCommitment: reactive.NewVariable[*model.Commitment](),
LatestCommitment: reactive.NewVariable[*model.Commitment](),
Workers: workers,
Expand Down Expand Up @@ -466,16 +466,7 @@ func (e *Engine) setupEvictionState() {
wp := e.Workers.CreatePool("EvictionState", workerpool.WithWorkerCount(1)) // Using just 1 worker to avoid contention

e.Events.BlockGadget.BlockAccepted.Hook(func(block *blocks.Block) {
block.ForEachParent(func(parent iotago.Parent) {
if parent.ID.Slot() < block.ID().Slot() && !e.EvictionState.IsRootBlock(parent.ID) {
parentBlock, exists := e.Block(parent.ID)
if !exists {
e.errorHandler(ierrors.Errorf("cannot store root block (%s) because it is missing", parent.ID))
return
}
e.EvictionState.AddRootBlock(parentBlock.ID(), parentBlock.ProtocolBlock().Header.SlotCommitmentID)
}
})
e.EvictionState.AddRootBlock(block.ID(), block.SlotCommitmentID())
}, event.WithWorkerPool(wp))

e.Events.Notarization.LatestCommitmentUpdated.Hook(func(commitment *model.Commitment) {
Expand Down
Loading

0 comments on commit f421d40

Please sign in to comment.