Skip to content

Commit

Permalink
Refactor: cleaned up more code
Browse files Browse the repository at this point in the history
  • Loading branch information
hmoog committed Nov 2, 2023
1 parent e9b7a2b commit 3c2ad4e
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 132 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-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/app v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/constraints v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/crypto v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/ds v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/ierrors v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/kvstore v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/lo v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/log v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/logger v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/runtime v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/stringify v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/ads v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/app v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/constraints v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231102194729-39400aaba459
github.com/iotaledger/hive.go/crypto v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/ds v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/ierrors v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/kvstore v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/lo v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/log v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/logger v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/runtime v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231102194729-39400aaba459
github.com/iotaledger/hive.go/stringify v0.0.0-20231102194729-39400aaba459
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-20231102135205-0f3d1e75042a h1:ORysxrc6QCG/uX0eHPmrl00isL+K37Gi7CPXWkWvKpA=
github.com/iotaledger/hive.go/ads v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:IFh0gDfeMgZtfCo+5afK59IDR4xXh+cTR9YtLnZPcbY=
github.com/iotaledger/hive.go/app v0.0.0-20231102135205-0f3d1e75042a h1:sNID0417k8UPZAHZjzx9cfPdDLD1J3EV89nWwRXkKA4=
github.com/iotaledger/hive.go/app v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:8ZbIKR84oQd/3iQ5eeT7xpudO9/ytzXP7veIYnk7Orc=
github.com/iotaledger/hive.go/constraints v0.0.0-20231102135205-0f3d1e75042a h1:kB5JFbOsZj/pBIcqnIMEnwk9XRBXZC6bEo08M6kFPaY=
github.com/iotaledger/hive.go/constraints v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231102135205-0f3d1e75042a h1:shooidIGLQm8wt7hzcx2hWXuC3ce4XLjIqB920R1V4U=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231102135205-0f3d1e75042a/go.mod h1:Mc+ACqBGPxrPMIPUBOm6/HL0J6m0iVMwjtIEKW3uow8=
github.com/iotaledger/hive.go/crypto v0.0.0-20231102135205-0f3d1e75042a h1:B1/zDZJDnBgCh+hwxzHyjGrUM1MTLumHwKZei+5Aehg=
github.com/iotaledger/hive.go/crypto v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:h3o6okvMSEK3KOX6pOp3yq1h9ohTkTfo6X8MzEadeb0=
github.com/iotaledger/hive.go/ds v0.0.0-20231102135205-0f3d1e75042a h1:hAsljqcUaL2ywSnztVBoaNh0cJwqaqNfPfTrUSLT9xo=
github.com/iotaledger/hive.go/ds v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:3XkUSKfHaVxGbT0XAvjNlVYqPzhfLTGhDtdNA5UBPco=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231102135205-0f3d1e75042a h1:c3XbjBDMiqo7jilZzZd+kmWrYvzufKmbHUOcOE3NpdI=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231102135205-0f3d1e75042a h1:2RZenapa2UI/Vj4vLNIlUgFUN1jJICV2XsZiIo9jQT4=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:O/U3jtiUDeqqM0MZQFu2UPqS9fUm0C5hNISxlmg/thE=
github.com/iotaledger/hive.go/lo v0.0.0-20231102135205-0f3d1e75042a h1:cHjCgpSdnrOCc69YPyntVVO+dFmVQh9kDj+rVpoJNlE=
github.com/iotaledger/hive.go/lo v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:s4kzx9QY1MVWHJralj+3q5kI0eARtrJhphYD/iBbPfo=
github.com/iotaledger/hive.go/log v0.0.0-20231102135205-0f3d1e75042a h1:PU+z5uVPUEVzmQf0JRLxJjnfMzdtz6mlnToECVzdVFQ=
github.com/iotaledger/hive.go/log v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:JvokzmpmFZPDskMlUqqjgHtD8usVJU4nAY/TNMGge8M=
github.com/iotaledger/hive.go/logger v0.0.0-20231102135205-0f3d1e75042a h1:8RigRlTTTBsT5Ik/Jz6VcLWgIzbx9HynzgnRq9/VhJE=
github.com/iotaledger/hive.go/logger v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:aBfAfIB2GO/IblhYt5ipCbyeL9bXSNeAwtYVA3hZaHg=
github.com/iotaledger/hive.go/runtime v0.0.0-20231102135205-0f3d1e75042a h1:vYyd5E4j02kwbAhx+nivcc7DPpmI46S72GBGGGpalSs=
github.com/iotaledger/hive.go/runtime v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:jRw8yFipiPaqmTPHh7hTcxAP9u6pjRGpByS3REJKkbY=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231102135205-0f3d1e75042a h1:/xwSejpRNjjv20gX9kQZ1Pgy+m6kFHcUMt1u/f+kc1Y=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231102135205-0f3d1e75042a/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231102135205-0f3d1e75042a h1:DNcRsEdvfnrfwh9Mb19lHfsz5Izf9BiMqJILYYW0SvU=
github.com/iotaledger/hive.go/stringify v0.0.0-20231102135205-0f3d1e75042a/go.mod h1:FTo/UWzNYgnQ082GI9QVM9HFDERqf9rw9RivNpqrnTs=
github.com/iotaledger/hive.go/ads v0.0.0-20231102194729-39400aaba459 h1:w9yXUcne7W7nWFa4w3z3Ab+CVm9XX6ootsKdj3h+Wy8=
github.com/iotaledger/hive.go/ads v0.0.0-20231102194729-39400aaba459/go.mod h1:IFh0gDfeMgZtfCo+5afK59IDR4xXh+cTR9YtLnZPcbY=
github.com/iotaledger/hive.go/app v0.0.0-20231102194729-39400aaba459 h1:Y4WcHH5njIV27r2SBD1V1EClz3iU3NDUC2xoU9+2Prw=
github.com/iotaledger/hive.go/app v0.0.0-20231102194729-39400aaba459/go.mod h1:8ZbIKR84oQd/3iQ5eeT7xpudO9/ytzXP7veIYnk7Orc=
github.com/iotaledger/hive.go/constraints v0.0.0-20231102194729-39400aaba459 h1:sI8mLL2Xrh4s414Zl0yWCUUNCEUNSiKeK7TG7GfW4J8=
github.com/iotaledger/hive.go/constraints v0.0.0-20231102194729-39400aaba459/go.mod h1:dOBOM2s4se3HcWefPe8sQLUalGXJ8yVXw58oK8jke3s=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231102194729-39400aaba459 h1:0w0NgTkXmMPYMPwbPydM8gZZGYMockp3sr9jYMR7iZc=
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231102194729-39400aaba459/go.mod h1:Mc+ACqBGPxrPMIPUBOm6/HL0J6m0iVMwjtIEKW3uow8=
github.com/iotaledger/hive.go/crypto v0.0.0-20231102194729-39400aaba459 h1:DuImYVscRKTXsYuVaGvfYpjmgWuHrLiji0LfYJ8wP7c=
github.com/iotaledger/hive.go/crypto v0.0.0-20231102194729-39400aaba459/go.mod h1:h3o6okvMSEK3KOX6pOp3yq1h9ohTkTfo6X8MzEadeb0=
github.com/iotaledger/hive.go/ds v0.0.0-20231102194729-39400aaba459 h1:UIj+JUgoD98oGej7two8mO9JqN6xOFb9HIT41Zi5yYQ=
github.com/iotaledger/hive.go/ds v0.0.0-20231102194729-39400aaba459/go.mod h1:3XkUSKfHaVxGbT0XAvjNlVYqPzhfLTGhDtdNA5UBPco=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231102194729-39400aaba459 h1:BEXcxjhYUpUweQ4m7LRwVQT7VQjXh10fNyqZIaASSBk=
github.com/iotaledger/hive.go/ierrors v0.0.0-20231102194729-39400aaba459/go.mod h1:HcE8B5lP96enc/OALTb2/rIIi+yOLouRoHOKRclKmC8=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231102194729-39400aaba459 h1:eC1RWb5+4ffPtXQPR+dLgN1rD/x3wQ8Da4zv6Wv/Zv0=
github.com/iotaledger/hive.go/kvstore v0.0.0-20231102194729-39400aaba459/go.mod h1:O/U3jtiUDeqqM0MZQFu2UPqS9fUm0C5hNISxlmg/thE=
github.com/iotaledger/hive.go/lo v0.0.0-20231102194729-39400aaba459 h1:SwhmyXn+MTXjr0ufeJNdsYlwBsYUpTTE1A0UiBUEnEE=
github.com/iotaledger/hive.go/lo v0.0.0-20231102194729-39400aaba459/go.mod h1:s4kzx9QY1MVWHJralj+3q5kI0eARtrJhphYD/iBbPfo=
github.com/iotaledger/hive.go/log v0.0.0-20231102194729-39400aaba459 h1:TZ0ja/3L2UZekbmH0frq0i4BiFElgFzJJs2HCaS2KfU=
github.com/iotaledger/hive.go/log v0.0.0-20231102194729-39400aaba459/go.mod h1:JvokzmpmFZPDskMlUqqjgHtD8usVJU4nAY/TNMGge8M=
github.com/iotaledger/hive.go/logger v0.0.0-20231102194729-39400aaba459 h1:EM4i81KcjyHQSOeRXgwtLTdHKdNcekZEfTrNkk2of+Q=
github.com/iotaledger/hive.go/logger v0.0.0-20231102194729-39400aaba459/go.mod h1:aBfAfIB2GO/IblhYt5ipCbyeL9bXSNeAwtYVA3hZaHg=
github.com/iotaledger/hive.go/runtime v0.0.0-20231102194729-39400aaba459 h1:RUU+I1d8KMhSgfGleWUU998K0S6lpNTg/3U0OXTim/Y=
github.com/iotaledger/hive.go/runtime v0.0.0-20231102194729-39400aaba459/go.mod h1:jRw8yFipiPaqmTPHh7hTcxAP9u6pjRGpByS3REJKkbY=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231102194729-39400aaba459 h1:dpGC+bnOhuZl7v4xHKe3EOsZC81Zs1+Ql7NoGVPPADU=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231102194729-39400aaba459/go.mod h1:SdK26z8/VhWtxaqCuQrufm80SELgowQPmu9T/8eUQ8g=
github.com/iotaledger/hive.go/stringify v0.0.0-20231102194729-39400aaba459 h1:X7eYICSvADXt2b38kV3fr/seEWpty/YxjpjruGmMyWw=
github.com/iotaledger/hive.go/stringify v0.0.0-20231102194729-39400aaba459/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
18 changes: 9 additions & 9 deletions pkg/protocol/commitment.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,18 @@ func NewCommitment(commitment *model.Commitment, protocol *Protocol) *Commitment
c.IsAttested.InheritFrom(c.IsRoot),
c.IsVerified.InheritFrom(c.IsRoot),

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

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

c.IsSolid.InheritFrom(parent.IsSolid),

c.Chain.DeriveValueFrom(reactive.NewDerivedVariable2(func(parentChain, spawnedChain *Chain) *Chain {
return lo.Cond(spawnedChain != nil, spawnedChain, parentChain)
}, parent.Chain, c.SpawnedChain)),

c.IsSolid.DeriveValueFrom(reactive.NewDerivedVariable(func(parentIsSolid bool) bool {
return parentIsSolid
}, parent.IsSolid)),

c.CumulativeAttestedWeight.DeriveValueFrom(reactive.NewDerivedVariable2(func(parentCumulativeAttestedWeight, attestedWeight uint64) uint64 {
return parentCumulativeAttestedWeight + attestedWeight
}, parent.CumulativeAttestedWeight, c.AttestedWeight)),
Expand All @@ -102,7 +100,7 @@ func NewCommitment(commitment *model.Commitment, protocol *Protocol) *Commitment
return parentAboveLatestVerifiedCommitment || (parentIsVerified && !isVerified)
}, parent.IsAboveLatestVerifiedCommitment, parent.IsVerified, c.IsVerified)),

reactive.WithNonEmptyValue(func(chain *Chain) func() {
c.Chain.WithNonEmptyValue(func(chain *Chain) func() {
return lo.Batch(
c.InSyncRange.DeriveValueFrom(reactive.NewDerivedVariable3(func(spawnedEngine *engine.Engine, warpSyncing, isAboveLatestVerifiedCommitment bool) bool {
return spawnedEngine != nil && !warpSyncing && isAboveLatestVerifiedCommitment
Expand All @@ -116,11 +114,13 @@ func NewCommitment(commitment *model.Commitment, protocol *Protocol) *Commitment
return verifyAttestations && parentIsAttested && !isAttested
}, chain.VerifyAttestations, parent.IsAttested, c.IsAttested)),
)
}, c.Chain),
}),
)
}, c.Parent),
}),

reactive.WithNonEmptyValue(func(chain *Chain) func() { return chain.registerCommitment(c) }, c.Chain),
c.Chain.WithNonEmptyValue(func(chain *Chain) func() {
return chain.registerCommitment(c)
}),
)

c.IsEvicted.OnTrigger(unsubscribe)
Expand Down
28 changes: 14 additions & 14 deletions tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
replace github.com/iotaledger/iota-core => ../../

require (
github.com/iotaledger/hive.go/app v0.0.0-20231102135205-0f3d1e75042a
github.com/iotaledger/hive.go/app v0.0.0-20231102194729-39400aaba459
github.com/iotaledger/hive.go/apputils v0.0.0-20230829152614-7afc7a4d89b3
github.com/iotaledger/iota-core v0.0.0-00010101000000-000000000000
)
Expand Down Expand Up @@ -56,19 +56,19 @@ 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/hive.go/ads v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/constraints v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/crypto v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/ds v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/ierrors v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/kvstore v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/lo v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/logger v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/runtime v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20231102135205-0f3d1e75042a // indirect
github.com/iotaledger/hive.go/ads v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/constraints v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/crypto v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/ds v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/ierrors v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/kvstore v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/lo v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/log v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/logger v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/runtime v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231102194729-39400aaba459 // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20231102194729-39400aaba459 // indirect
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231031135002-4c79ea5193f5 // indirect
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231031134131-b6ad918dc1ac // indirect
github.com/iotaledger/iota.go/v4 v4.0.0-20231102113728-20b8d01e826e // indirect
Expand Down
Loading

0 comments on commit 3c2ad4e

Please sign in to comment.