Skip to content

Commit

Permalink
Feat: upgraded to hive
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Nov 8, 2023
1 parent 8740c32 commit f072485
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 168 deletions.
28 changes: 14 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ require (
github.com/google/uuid v1.4.0
github.com/gorilla/websocket v1.5.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/iotaledger/hive.go/ads v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/app v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/constraints v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231107225803-f89acd088c10
github.com/iotaledger/hive.go/crypto v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/ds v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/ierrors v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/kvstore v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/lo v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/log v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/logger v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/runtime v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231107225803-f89acd088c10
github.com/iotaledger/hive.go/stringify v0.0.0-20231107225803-f89acd088c10
github.com/iotaledger/hive.go/ads v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/app v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/constraints v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231108145121-e1914a65274b
github.com/iotaledger/hive.go/crypto v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/ds v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/ierrors v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/kvstore v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/lo v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/log v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/logger v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/runtime v0.0.0-20231108145121-e1914a65274b
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231108145121-e1914a65274b
github.com/iotaledger/hive.go/stringify v0.0.0-20231108145121-e1914a65274b
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-20231102113728-20b8d01e826e
Expand Down
56 changes: 28 additions & 28 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,34 +275,34 @@ github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJ
github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 h1:dTrD7X2PTNgli6EbS4tV9qu3QAm/kBU3XaYZV2xdzys=
github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7/go.mod h1:ZRdPu684P0fQ1z8sXz4dj9H5LWHhz4a9oCtvjunkSrw=
github.com/iotaledger/hive.go/ads v0.0.0-20231107225803-f89acd088c10 h1:M24zuxsCGccvksoanDZEjc8K3tWFyw7aZ2sbQK740pE=
github.com/iotaledger/hive.go/ads v0.0.0-20231107225803-f89acd088c10/go.mod h1:IFh0gDfeMgZtfCo+5afK59IDR4xXh+cTR9YtLnZPcbY=
github.com/iotaledger/hive.go/app v0.0.0-20231107225803-f89acd088c10 h1:wsUsKHP9meQsr1UPYASpN+QRa2NlWyhDbt0R310NccM=
github.com/iotaledger/hive.go/app v0.0.0-20231107225803-f89acd088c10/go.mod h1:8ZbIKR84oQd/3iQ5eeT7xpudO9/ytzXP7veIYnk7Orc=
github.com/iotaledger/hive.go/constraints v0.0.0-20231107225803-f89acd088c10 h1:CJ9nehCDKqFo3sJLMnybx0/AvmdXq6dau5qFr+pivUc=
github.com/iotaledger/hive.go/constraints v0.0.0-20231107225803-f89acd088c10/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231107225803-f89acd088c10 h1:FMassldB6buYv8nsfELSkKzR3mj326YNmLy4DNY+20o=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231107225803-f89acd088c10/go.mod h1:Mc+ACqBGPxrPMIPUBOm6/HL0J6m0iVMwjtIEKW3uow8=
github.com/iotaledger/hive.go/crypto v0.0.0-20231107225803-f89acd088c10 h1:sGxsehUXmhWW5Vv9PBwuW1mlW2Npdb2yMonZgolVzHs=
github.com/iotaledger/hive.go/crypto v0.0.0-20231107225803-f89acd088c10/go.mod h1:h3o6okvMSEK3KOX6pOp3yq1h9ohTkTfo6X8MzEadeb0=
github.com/iotaledger/hive.go/ds v0.0.0-20231107225803-f89acd088c10 h1:NufkzT29n9OconEE6+8HMoCkW+MXiznGn+HxWrNPy1o=
github.com/iotaledger/hive.go/ds v0.0.0-20231107225803-f89acd088c10/go.mod h1:3XkUSKfHaVxGbT0XAvjNlVYqPzhfLTGhDtdNA5UBPco=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231107225803-f89acd088c10 h1:M43fs0ybJXyVGnN55xG2OrMmXqbpYGudnU8zIA7NNL4=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231107225803-f89acd088c10/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231107225803-f89acd088c10 h1:nGffY7n3mxUFtWrKgbvNx7jYu2lGkeu01hp+8aLaOk8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231107225803-f89acd088c10/go.mod h1:O/U3jtiUDeqqM0MZQFu2UPqS9fUm0C5hNISxlmg/thE=
github.com/iotaledger/hive.go/lo v0.0.0-20231107225803-f89acd088c10 h1:ME7iE4yKMYEvfkFvOPswAWsZaq7mLkKiGN88K1X1OBg=
github.com/iotaledger/hive.go/lo v0.0.0-20231107225803-f89acd088c10/go.mod h1:s4kzx9QY1MVWHJralj+3q5kI0eARtrJhphYD/iBbPfo=
github.com/iotaledger/hive.go/log v0.0.0-20231107225803-f89acd088c10 h1:yhDHLCtdpLSiv/kDDLDkJZcJispd1OUAWIYF7RXFQi4=
github.com/iotaledger/hive.go/log v0.0.0-20231107225803-f89acd088c10/go.mod h1:JvokzmpmFZPDskMlUqqjgHtD8usVJU4nAY/TNMGge8M=
github.com/iotaledger/hive.go/logger v0.0.0-20231107225803-f89acd088c10 h1:ajaTrqlYEjVbkIu2RTN+GKrQnbbbjoAFea2wLgj2B+c=
github.com/iotaledger/hive.go/logger v0.0.0-20231107225803-f89acd088c10/go.mod h1:aBfAfIB2GO/IblhYt5ipCbyeL9bXSNeAwtYVA3hZaHg=
github.com/iotaledger/hive.go/runtime v0.0.0-20231107225803-f89acd088c10 h1:5tPaO+hxPTBp5J7Ap2oIqzHEXmYbrh5Rfh4y2l5KaQQ=
github.com/iotaledger/hive.go/runtime v0.0.0-20231107225803-f89acd088c10/go.mod h1:jRw8yFipiPaqmTPHh7hTcxAP9u6pjRGpByS3REJKkbY=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231107225803-f89acd088c10 h1:KahaknpEVnJCgyaawYzRVR0rcX2/iCXiUXHvSjlMqEA=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231107225803-f89acd088c10/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231107225803-f89acd088c10 h1:1BQfYB6hxWGTjrv70SP3xxThxTV8t1AqEVQRRr5dTJI=
github.com/iotaledger/hive.go/stringify v0.0.0-20231107225803-f89acd088c10/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/hive.go/ads v0.0.0-20231108145121-e1914a65274b h1:QWGaBbcd6kdgUNvYTdsb1Jz7dW8z4KhYl8XTrVBcjMU=
github.com/iotaledger/hive.go/ads v0.0.0-20231108145121-e1914a65274b/go.mod h1:IFh0gDfeMgZtfCo+5afK59IDR4xXh+cTR9YtLnZPcbY=
github.com/iotaledger/hive.go/app v0.0.0-20231108145121-e1914a65274b h1:NMyLeKTws/cCnLRWeqRQfOlN0DnKTi/MOu15wNJKZCA=
github.com/iotaledger/hive.go/app v0.0.0-20231108145121-e1914a65274b/go.mod h1:8ZbIKR84oQd/3iQ5eeT7xpudO9/ytzXP7veIYnk7Orc=
github.com/iotaledger/hive.go/constraints v0.0.0-20231108145121-e1914a65274b h1:TFmdanDRuGQsuiQ92+kCSrV9G8hFF281odflmZ+Cz+g=
github.com/iotaledger/hive.go/constraints v0.0.0-20231108145121-e1914a65274b/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231108145121-e1914a65274b h1:W0M/VoJeqxD331urc4NOHlX5Sij/ZdrNwM/ZZkyV7h0=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231108145121-e1914a65274b/go.mod h1:Mc+ACqBGPxrPMIPUBOm6/HL0J6m0iVMwjtIEKW3uow8=
github.com/iotaledger/hive.go/crypto v0.0.0-20231108145121-e1914a65274b h1:IZBnVPVNG9PLKO975XGRN+YBMgMBxD/5lwv2dsttLFg=
github.com/iotaledger/hive.go/crypto v0.0.0-20231108145121-e1914a65274b/go.mod h1:h3o6okvMSEK3KOX6pOp3yq1h9ohTkTfo6X8MzEadeb0=
github.com/iotaledger/hive.go/ds v0.0.0-20231108145121-e1914a65274b h1:87KrKSFG9gptutDPj9b/c0YsILu01EIodkuppfppjaE=
github.com/iotaledger/hive.go/ds v0.0.0-20231108145121-e1914a65274b/go.mod h1:3XkUSKfHaVxGbT0XAvjNlVYqPzhfLTGhDtdNA5UBPco=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231108145121-e1914a65274b h1:9ybKrUkZBUoAPohf4nvzklCZkM1KGQ1eY5zq25VwRLY=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231108145121-e1914a65274b/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231108145121-e1914a65274b h1:l5pjwnk9HIjI2a5j4H0Q7pi/AzFuZDrQTY+rT3PxXzE=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231108145121-e1914a65274b/go.mod h1:O/U3jtiUDeqqM0MZQFu2UPqS9fUm0C5hNISxlmg/thE=
github.com/iotaledger/hive.go/lo v0.0.0-20231108145121-e1914a65274b h1:P9L6XTDGsQ+bUrca+oAUQHC+iHzob883Yc8O0NRd3YQ=
github.com/iotaledger/hive.go/lo v0.0.0-20231108145121-e1914a65274b/go.mod h1:s4kzx9QY1MVWHJralj+3q5kI0eARtrJhphYD/iBbPfo=
github.com/iotaledger/hive.go/log v0.0.0-20231108145121-e1914a65274b h1:zaZ4MqNOvriaUvksEH4tH46LcCeT3weiuj/wHnQycMI=
github.com/iotaledger/hive.go/log v0.0.0-20231108145121-e1914a65274b/go.mod h1:JvokzmpmFZPDskMlUqqjgHtD8usVJU4nAY/TNMGge8M=
github.com/iotaledger/hive.go/logger v0.0.0-20231108145121-e1914a65274b h1:o/FIpPxgmB/S69FlbbDpkJiUNt7VUNq+TITTsVwCIfc=
github.com/iotaledger/hive.go/logger v0.0.0-20231108145121-e1914a65274b/go.mod h1:aBfAfIB2GO/IblhYt5ipCbyeL9bXSNeAwtYVA3hZaHg=
github.com/iotaledger/hive.go/runtime v0.0.0-20231108145121-e1914a65274b h1:zucA1sAW/XD/NzhXtyrPuwDYBvVR0tI0jVF5fPOj51o=
github.com/iotaledger/hive.go/runtime v0.0.0-20231108145121-e1914a65274b/go.mod h1:jRw8yFipiPaqmTPHh7hTcxAP9u6pjRGpByS3REJKkbY=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231108145121-e1914a65274b h1:c4N8q7GzrExCcFAn/xtd074k5FzabKh3/XPIEDMNILk=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231108145121-e1914a65274b/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231108145121-e1914a65274b h1:vrOyDF4OeTcnyCRwpdAT+cdo1G3aEhljLZbKmQn6Dwg=
github.com/iotaledger/hive.go/stringify v0.0.0-20231108145121-e1914a65274b/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=
Expand Down
106 changes: 65 additions & 41 deletions pkg/protocol/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Commitment struct {
SpawnedChain reactive.Variable[*Chain]
Chain reactive.Variable[*Chain]
RequestAttestations reactive.Variable[bool]
WarpSync reactive.Variable[bool]
WarpSyncBlocks reactive.Variable[bool]
RequestedBlocksReceived reactive.Variable[bool]
Weight reactive.Variable[uint64]
AttestedWeight reactive.Variable[uint64]
Expand All @@ -27,26 +27,23 @@ type Commitment struct {
IsAttested reactive.Event
IsVerified reactive.Event
IsAboveLatestVerifiedCommitment reactive.Variable[bool]
InSyncRange reactive.Variable[bool]
ReplayDroppedBlocks reactive.Variable[bool]
IsEvicted reactive.Event

protocol *Protocol

*model.Commitment

log.Logger
}

func NewCommitment(commitment *model.Commitment, protocol *Protocol) *Commitment {
c := &Commitment{
return (&Commitment{
Commitment: commitment,
Parent: reactive.NewVariable[*Commitment](),
Children: reactive.NewSet[*Commitment](),
MainChild: reactive.NewVariable[*Commitment](),
SpawnedChain: reactive.NewVariable[*Chain](),
Chain: reactive.NewVariable[*Chain](),
RequestAttestations: reactive.NewVariable[bool](),
WarpSync: reactive.NewVariable[bool](),
WarpSyncBlocks: reactive.NewVariable[bool](),
RequestedBlocksReceived: reactive.NewVariable[bool](),
Weight: reactive.NewVariable[uint64](),
AttestedWeight: reactive.NewVariable[uint64](func(currentValue uint64, newValue uint64) uint64 { return max(currentValue, newValue) }),
Expand All @@ -56,44 +53,59 @@ func NewCommitment(commitment *model.Commitment, protocol *Protocol) *Commitment
IsAttested: reactive.NewEvent(),
IsVerified: reactive.NewEvent(),
IsAboveLatestVerifiedCommitment: reactive.NewVariable[bool](),
InSyncRange: reactive.NewVariable[bool](),
ReplayDroppedBlocks: reactive.NewVariable[bool](),
IsEvicted: reactive.NewEvent(),
}).initLogging(protocol).initBehavior(protocol)
}

func (c *Commitment) Engine() *engine.Engine {
if chain := c.Chain.Get(); chain != nil {
return chain.Engine.Get()
}

c.Logger = protocol.NewEntityLogger(fmt.Sprintf("Slot%d.", commitment.Slot()), c.IsEvicted, func(entityLogger log.Logger) {
c.Parent.LogUpdates(c, log.LevelTrace, "Parent", (*Commitment).LogName)
// c.Children.LogUpdates(entityLogger, log.LevelTrace, "Children", (*Commitment).LogName)
c.MainChild.LogUpdates(entityLogger, log.LevelTrace, "MainChild", (*Commitment).LogName)
c.SpawnedChain.LogUpdates(entityLogger, log.LevelTrace, "SpawnedChain", (*Chain).LogName)
c.Chain.LogUpdates(entityLogger, log.LevelTrace, "Chain", (*Chain).LogName)
c.RequestAttestations.LogUpdates(entityLogger, log.LevelTrace, "RequestAttestations")
c.WarpSync.LogUpdates(entityLogger, log.LevelTrace, "WarpSync")
c.RequestedBlocksReceived.LogUpdates(entityLogger, log.LevelTrace, "RequestedBlocksReceived")
c.Weight.LogUpdates(entityLogger, log.LevelTrace, "Weight")
c.AttestedWeight.LogUpdates(entityLogger, log.LevelTrace, "AttestedWeight")
c.CumulativeAttestedWeight.LogUpdates(entityLogger, log.LevelTrace, "CumulativeAttestedWeight")
c.IsRoot.LogUpdates(entityLogger, log.LevelTrace, "IsRoot")
c.IsSolid.LogUpdates(entityLogger, log.LevelTrace, "IsSolid")
c.IsAttested.LogUpdates(entityLogger, log.LevelTrace, "IsAttested")
c.IsVerified.LogUpdates(entityLogger, log.LevelTrace, "IsVerified")
c.InSyncRange.LogUpdates(entityLogger, log.LevelTrace, "InSyncRange")
c.IsEvicted.LogUpdates(entityLogger, log.LevelTrace, "IsEvicted")
})
return nil
}

func (c *Commitment) initLogging(protocol *Protocol) (self *Commitment) {
c.Logger = protocol.NewEntityLogger(fmt.Sprintf("Slot%d.", c.Slot()), c.IsEvicted, func(_ log.Logger) {})

teardownLogging := lo.Batch(
c.Parent.LogUpdates(c, log.LevelTrace, "Parent", (*Commitment).LogName),
// c.Children.LogUpdates(c, log.LevelTrace, "Children", (*Commitment).LogName),
c.MainChild.LogUpdates(c, log.LevelTrace, "MainChild", (*Commitment).LogName),
c.SpawnedChain.LogUpdates(c, log.LevelTrace, "SpawnedChain", (*Chain).LogName),
c.Chain.LogUpdates(c, log.LevelTrace, "Chain", (*Chain).LogName),
c.RequestAttestations.LogUpdates(c, log.LevelTrace, "RequestAttestations"),
c.WarpSyncBlocks.LogUpdates(c, log.LevelTrace, "WarpSyncBlocks"),
c.RequestedBlocksReceived.LogUpdates(c, log.LevelTrace, "RequestedBlocksReceived"),
c.Weight.LogUpdates(c, log.LevelTrace, "Weight"),
c.AttestedWeight.LogUpdates(c, log.LevelTrace, "AttestedWeight"),
c.CumulativeAttestedWeight.LogUpdates(c, log.LevelTrace, "CumulativeAttestedWeight"),
c.IsRoot.LogUpdates(c, log.LevelTrace, "IsRoot"),
c.IsSolid.LogUpdates(c, log.LevelTrace, "IsSolid"),
c.IsAttested.LogUpdates(c, log.LevelTrace, "IsAttested"),
c.IsVerified.LogUpdates(c, log.LevelTrace, "IsVerified"),
c.ReplayDroppedBlocks.LogUpdates(c, log.LevelTrace, "ReplayDroppedBlocks"),
c.IsEvicted.LogUpdates(c, log.LevelTrace, "IsEvicted"),
)

c.IsEvicted.OnTrigger(teardownLogging)

return c
}

unsubscribe := lo.Batch(
func (c *Commitment) initBehavior(protocol *Protocol) (self *Commitment) {
teardownBehavior := lo.Batch(
c.IsSolid.InheritFrom(c.IsRoot),
c.IsAttested.InheritFrom(c.IsRoot),
c.IsVerified.InheritFrom(c.IsRoot),

c.Parent.WithNonEmptyValue(func(parent *Commitment) func() {
c.Weight.Set(c.CumulativeWeight() - parent.CumulativeWeight())

// TODO: REMOVE ON UNSUBSCRIBE
parent.MainChild.Compute(func(mainChild *Commitment) *Commitment {
return lo.Cond(mainChild != nil, mainChild, c)
})

return lo.Batch(
parent.registerChild(c),

c.SpawnedChain.DeriveValueFrom(reactive.NewDerivedVariable2(func(spawnedChain *Chain, isRoot bool, mainChild *Commitment) *Chain {
if !isRoot { // do not adjust the chain of the root commitment
if mainChild != c {
Expand Down Expand Up @@ -128,11 +140,11 @@ func NewCommitment(commitment *model.Commitment, protocol *Protocol) *Commitment

c.Chain.WithNonEmptyValue(func(chain *Chain) func() {
return lo.Batch(
c.InSyncRange.DeriveValueFrom(reactive.NewDerivedVariable3(func(_ bool, spawnedEngine *engine.Engine, warpSyncing, isAboveLatestVerifiedCommitment bool) bool {
c.ReplayDroppedBlocks.DeriveValueFrom(reactive.NewDerivedVariable3(func(_ bool, spawnedEngine *engine.Engine, warpSyncing, isAboveLatestVerifiedCommitment bool) bool {
return spawnedEngine != nil && !warpSyncing && isAboveLatestVerifiedCommitment
}, chain.SpawnedEngine, chain.WarpSync, c.IsAboveLatestVerifiedCommitment)),

c.WarpSync.DeriveValueFrom(reactive.NewDerivedVariable4(func(_ bool, spawnedEngine *engine.Engine, warpSync, parentIsVerified, isVerified bool) bool {
c.WarpSyncBlocks.DeriveValueFrom(reactive.NewDerivedVariable4(func(_ bool, spawnedEngine *engine.Engine, warpSync, parentIsVerified, isVerified bool) bool {
return spawnedEngine != nil && warpSync && parentIsVerified && !isVerified
}, chain.SpawnedEngine, chain.WarpSync, parent.IsVerified, c.IsVerified)),

Expand All @@ -149,17 +161,29 @@ func NewCommitment(commitment *model.Commitment, protocol *Protocol) *Commitment
}),
)

c.IsEvicted.OnTrigger(unsubscribe)
c.IsEvicted.OnTrigger(teardownBehavior)

return c
}

func (c *Commitment) Engine() *engine.Engine {
if chain := c.Chain.Get(); chain != nil {
return chain.Engine.Get()
}
func (c *Commitment) registerChild(child *Commitment) (unregisterChild func()) {
c.MainChild.Compute(func(mainChild *Commitment) *Commitment {
if !c.Children.Add(child) || mainChild != nil {
return mainChild
}

return nil
return child
})

return func() {
c.MainChild.Compute(func(mainChild *Commitment) *Commitment {
if !c.Children.Delete(child) || child != mainChild {
return mainChild
}

return lo.Return1(c.Children.Any())
})
}
}

func (c *Commitment) setChain(targetChain *Chain) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/protocol/protocol_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewBlocksProtocol(protocol *Protocol) *BlocksProtocol {

protocol.Constructed.OnTrigger(func() {
protocol.CommitmentCreated.Hook(func(commitment *Commitment) {
commitment.InSyncRange.OnUpdate(func(_, replayBlocks bool) {
commitment.ReplayDroppedBlocks.OnUpdate(func(_, replayBlocks bool) {
if replayBlocks {
b.LogDebug("replaying blocks", "commitmentID", commitment.ID())

Expand Down
4 changes: 2 additions & 2 deletions pkg/protocol/protocol_warp_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewWarpSyncProtocol(protocol *Protocol) *WarpSyncProtocol {

protocol.Constructed.OnTrigger(func() {
c.protocol.CommitmentCreated.Hook(func(commitment *Commitment) {
commitment.WarpSync.OnUpdate(func(_, warpSyncBlocks bool) {
commitment.WarpSyncBlocks.OnUpdate(func(_, warpSyncBlocks bool) {
if warpSyncBlocks {
c.ticker.StartTicker(commitment.ID())
} else {
Expand Down Expand Up @@ -101,7 +101,7 @@ func (w *WarpSyncProtocol) ProcessResponse(commitmentID iotago.CommitmentID, blo
}

commitment.RequestedBlocksReceived.Compute(func(requestedBlocksReceived bool) bool {
if requestedBlocksReceived || !commitment.WarpSync.Get() {
if requestedBlocksReceived || !commitment.WarpSyncBlocks.Get() {
w.LogTrace("response for already synced commitment", "commitment", commitment.LogName(), "fromPeer", from)

return requestedBlocksReceived
Expand Down
Loading

0 comments on commit f072485

Please sign in to comment.