Skip to content

Commit

Permalink
Merge pull request #2443 from iotaledger/fix/reboot-cluster-tests
Browse files Browse the repository at this point in the history
Fix reboot cluster tests
  • Loading branch information
muXxer authored May 8, 2023
2 parents 5dab9f2 + a474bf3 commit 5e7b5a6
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 215 deletions.
36 changes: 0 additions & 36 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -350,52 +350,28 @@ github.com/iotaledger/go-ethereum v1.10.26-wasp h1:OycFPMpnmGli5La0SdYzgnn4xqC8O
github.com/iotaledger/go-ethereum v1.10.26-wasp/go.mod h1:EYFyF19u3ezGLD4RqOkLq+ZCXzYbLoNDdZlMt7kyKFg=
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/app v0.0.0-20230420105138-0b7cba751091 h1:RRaAwytC7npyq9jSUug9MDyJvq9Vc1sUQ7ilM5aPoCQ=
github.com/iotaledger/hive.go/app v0.0.0-20230420105138-0b7cba751091/go.mod h1:vMXrLYkkHAqQC8yGLXcB1Adq9s3hPPf8Dv4sfd/koas=
github.com/iotaledger/hive.go/app v0.0.0-20230425142119-6abddaf15db9 h1:vdVG068l2cDUuyUSrdKRG9IZOSii74t5iWyrwfr0utc=
github.com/iotaledger/hive.go/app v0.0.0-20230425142119-6abddaf15db9/go.mod h1:vMXrLYkkHAqQC8yGLXcB1Adq9s3hPPf8Dv4sfd/koas=
github.com/iotaledger/hive.go/constraints v0.0.0-20230420105138-0b7cba751091 h1:lrk4idgU9um+C6b4pcAlfQ9pHqhlR0fKH0TqZ9XU4QU=
github.com/iotaledger/hive.go/constraints v0.0.0-20230420105138-0b7cba751091/go.mod h1:bvXXc6quBdERMMKnirr2+iQU4WnTz4KDbdHcusW9Ats=
github.com/iotaledger/hive.go/constraints v0.0.0-20230425142119-6abddaf15db9 h1:cADhnifbOeGuGZfAw+QYq1DdRYSWxOQpq3fRzhN3aaE=
github.com/iotaledger/hive.go/constraints v0.0.0-20230425142119-6abddaf15db9/go.mod h1:bvXXc6quBdERMMKnirr2+iQU4WnTz4KDbdHcusW9Ats=
github.com/iotaledger/hive.go/crypto v0.0.0-20230420105138-0b7cba751091 h1:AkBHLVkKD4inbZJAPeisNH9f7R58oyAbZCqQdMFh6bY=
github.com/iotaledger/hive.go/crypto v0.0.0-20230420105138-0b7cba751091/go.mod h1:xp9Wbk2vp4LHb0xTbDRphSJLgLYvRNNe5lWHd8OLI5c=
github.com/iotaledger/hive.go/crypto v0.0.0-20230425142119-6abddaf15db9 h1:oXs44XoTd5IK6qy1Mcu/O607FGqH52RIAiCNBSExizA=
github.com/iotaledger/hive.go/crypto v0.0.0-20230425142119-6abddaf15db9/go.mod h1:xp9Wbk2vp4LHb0xTbDRphSJLgLYvRNNe5lWHd8OLI5c=
github.com/iotaledger/hive.go/ds v0.0.0-20230420105138-0b7cba751091 h1:OfZSvOvdEI/FKbMrorBtsXGceXJeD0zrU5vL6dYbAIg=
github.com/iotaledger/hive.go/ds v0.0.0-20230420105138-0b7cba751091/go.mod h1:wwPP73b6InomUeirqEfaYNqoTsuzxNZPa/ci4efzuyU=
github.com/iotaledger/hive.go/ds v0.0.0-20230425142119-6abddaf15db9 h1:r0jnucfIUmtk1+y0gpWCga0z2XVHuxaWIZOr8m+2E28=
github.com/iotaledger/hive.go/ds v0.0.0-20230425142119-6abddaf15db9/go.mod h1:wwPP73b6InomUeirqEfaYNqoTsuzxNZPa/ci4efzuyU=
github.com/iotaledger/hive.go/kvstore v0.0.0-20230420105138-0b7cba751091 h1:2hAbM0ZtPOecnBtd3hcPcRlLKxu3UEoRKBXXNfIz608=
github.com/iotaledger/hive.go/kvstore v0.0.0-20230420105138-0b7cba751091/go.mod h1:oET9GdiN58SWw+INHuNwmiBlfmfRyoe1cJMx7TYk1Js=
github.com/iotaledger/hive.go/kvstore v0.0.0-20230425142119-6abddaf15db9 h1:Qhgbik2YYYLik1AAb9newLNRvO3XMhdj1FOe1wHho0U=
github.com/iotaledger/hive.go/kvstore v0.0.0-20230425142119-6abddaf15db9/go.mod h1:oET9GdiN58SWw+INHuNwmiBlfmfRyoe1cJMx7TYk1Js=
github.com/iotaledger/hive.go/lo v0.0.0-20230420105138-0b7cba751091 h1:zV629ikyaU6n7CkWP7qOuJyCGh6yBcqWDiPKNB25Ago=
github.com/iotaledger/hive.go/lo v0.0.0-20230420105138-0b7cba751091/go.mod h1:dsAfSt53PGgT3n675q2wFLGcvRlLNS3Affhf+vnFbb4=
github.com/iotaledger/hive.go/lo v0.0.0-20230425142119-6abddaf15db9 h1:mAifrfqpzx4AGvvdr7yEJ3GQUmEjUBlkzVoLk6+79Bc=
github.com/iotaledger/hive.go/lo v0.0.0-20230425142119-6abddaf15db9/go.mod h1:dsAfSt53PGgT3n675q2wFLGcvRlLNS3Affhf+vnFbb4=
github.com/iotaledger/hive.go/logger v0.0.0-20230420105138-0b7cba751091 h1:Raj6J9Hj3dVUV15uqPl7/ZD2iDNVGyuIhpSpWvR8Ieg=
github.com/iotaledger/hive.go/logger v0.0.0-20230420105138-0b7cba751091/go.mod h1:7ZE+E8JgqJ9zxg5/FOObEfYyBpC813TMv6Qzcm2YekY=
github.com/iotaledger/hive.go/logger v0.0.0-20230425142119-6abddaf15db9 h1:50uDxTKB/HWMhAhzognCBoY+xf4pOEKNaznoIqc2D1g=
github.com/iotaledger/hive.go/logger v0.0.0-20230425142119-6abddaf15db9/go.mod h1:7ZE+E8JgqJ9zxg5/FOObEfYyBpC813TMv6Qzcm2YekY=
github.com/iotaledger/hive.go/objectstorage v0.0.0-20230420105138-0b7cba751091 h1:Ob67YuV7XiyiGWVXTrTCwclkLZ1d/rVGNTpGUgloYG8=
github.com/iotaledger/hive.go/objectstorage v0.0.0-20230420105138-0b7cba751091/go.mod h1:E7/slsvlTsSP+laCKWbBOmSPg83UTh9mPm8ostFOlv4=
github.com/iotaledger/hive.go/objectstorage v0.0.0-20230425142119-6abddaf15db9 h1:apDCJqkZ+GMR7Cui5nycKD18+ykKagXCMakAAoGBt6U=
github.com/iotaledger/hive.go/objectstorage v0.0.0-20230425142119-6abddaf15db9/go.mod h1:E7/slsvlTsSP+laCKWbBOmSPg83UTh9mPm8ostFOlv4=
github.com/iotaledger/hive.go/runtime v0.0.0-20230420105138-0b7cba751091 h1:ysxbEbYN1RR4DpzZoWOE5dLwMv8ZoAhi6Hyq2HIF8dE=
github.com/iotaledger/hive.go/runtime v0.0.0-20230420105138-0b7cba751091/go.mod h1:kYmuL6D9aDLqLpskEEC+DGKXC/9mx7wtLF0WItRuexs=
github.com/iotaledger/hive.go/runtime v0.0.0-20230425142119-6abddaf15db9 h1:yZH3ZhwbUlmefsY4WjOuSHIGIxZVUEHcGbe24rvwa+Y=
github.com/iotaledger/hive.go/runtime v0.0.0-20230425142119-6abddaf15db9/go.mod h1:kYmuL6D9aDLqLpskEEC+DGKXC/9mx7wtLF0WItRuexs=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230420105138-0b7cba751091 h1:3C/85Jq/OCUcZueARe1rqrkb6lKD5V1eSkVqf30EWFs=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230420105138-0b7cba751091/go.mod h1:NrZTRu5hrKwSxzPyA5G8BxaQakOLRvoFJM+5vtHDE04=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230425142119-6abddaf15db9 h1:AF3u8en9xETBK14nByOFrk7rY1aRJBzlGo+8k9VqEIQ=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20230425142119-6abddaf15db9/go.mod h1:NrZTRu5hrKwSxzPyA5G8BxaQakOLRvoFJM+5vtHDE04=
github.com/iotaledger/hive.go/stringify v0.0.0-20230420105138-0b7cba751091 h1:0fdrjKNuETsb/YXTqjeuDTNIEC/Zon8Cd0tdnTj2zG0=
github.com/iotaledger/hive.go/stringify v0.0.0-20230420105138-0b7cba751091/go.mod h1:l/F3cA/+67QdNj+sohv2v4HhmsdOcWScoA+sVYoAE4c=
github.com/iotaledger/hive.go/stringify v0.0.0-20230425142119-6abddaf15db9 h1:JWv+DePobyjR5K1tzE2w7bs79WzBLMuxYLIFC3idPvA=
github.com/iotaledger/hive.go/stringify v0.0.0-20230425142119-6abddaf15db9/go.mod h1:l/F3cA/+67QdNj+sohv2v4HhmsdOcWScoA+sVYoAE4c=
github.com/iotaledger/hive.go/web v0.0.0-20230420105138-0b7cba751091 h1:A+ZD2CRRGMUXvIZXfT3OvWqnrgsOPWL41OeR9w9XkD4=
github.com/iotaledger/hive.go/web v0.0.0-20230420105138-0b7cba751091/go.mod h1:A3LLvpa7mREy3eWZf+UsD1A1ujo4YZHK+e2IHvou+HQ=
github.com/iotaledger/hive.go/web v0.0.0-20230425142119-6abddaf15db9 h1:c6WCBtoUI4hBHxx9wnAqHjiCBiNsTE5mOUq+bZN0X1E=
github.com/iotaledger/hive.go/web v0.0.0-20230425142119-6abddaf15db9/go.mod h1:A3LLvpa7mREy3eWZf+UsD1A1ujo4YZHK+e2IHvou+HQ=
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20230417131029-0bfe891d7c4a h1:mVYBXnSSVl9xRxzZReRdRQN43gUz3IMOxb+IEMQFTp4=
Expand Down Expand Up @@ -494,8 +470,6 @@ github.com/libp2p/go-cidranger v1.1.0 h1:ewPN8EZ0dd1LSnrtuwd4709PXVcITVeuwbag38y
github.com/libp2p/go-cidranger v1.1.0/go.mod h1:KWZTfSr+r9qEo9OkI9/SIEeAtw+NNoU0dXIXt15Okic=
github.com/libp2p/go-flow-metrics v0.1.0 h1:0iPhMI8PskQwzh57jB9WxIuIOQ0r+15PChFGkx3Q3WM=
github.com/libp2p/go-flow-metrics v0.1.0/go.mod h1:4Xi8MX8wj5aWNDAZttg6UPmc0ZrnFNsMtpsYUClFtro=
github.com/libp2p/go-libp2p v0.27.1 h1:k1u6RHsX3hqKnslDjsSgLNURxJ3O1atIZCY4gpMbbus=
github.com/libp2p/go-libp2p v0.27.1/go.mod h1:FAvvfQa/YOShUYdiSS03IR9OXzkcJXwcNA2FUCh9ImE=
github.com/libp2p/go-libp2p v0.27.2 h1:I1fxqxdm/O0TFoAZKje8wSMu9tfLlLdzTQvgT3HA6v0=
github.com/libp2p/go-libp2p v0.27.2/go.mod h1:FAvvfQa/YOShUYdiSS03IR9OXzkcJXwcNA2FUCh9ImE=
github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s=
Expand Down Expand Up @@ -680,8 +654,6 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.15.0 h1:5fCgGYogn0hFdhyhLbw7hEsWxufKtY9klyvdNfFlFhM=
github.com/prometheus/client_golang v1.15.0/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_golang v1.15.1 h1:8tXpTmJbyH5lydzFPoxSIJ0J46jdh3tylbvM1xCv0LI=
github.com/prometheus/client_golang v1.15.1/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
Expand Down Expand Up @@ -743,8 +715,6 @@ github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71e
github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM=
github.com/schollz/closestmatch v2.1.0+incompatible/go.mod h1:RtP1ddjLong6gTkbtmuhtR2uUrrJOpYzYRvbcPAid+g=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/second-state/WasmEdge-go v0.11.2 h1:4RZhxKvay9uBM9uzE0jrB/26t1ncQG3LbNQOooKjrHA=
github.com/second-state/WasmEdge-go v0.11.2/go.mod h1:HyBf9hVj1sRAjklsjc1Yvs9b5RcmthPG9z99dY78TKg=
github.com/second-state/WasmEdge-go v0.12.0 h1:CJFH/rwZMXIX/UeX4CRUzbcTUlXJfFNZTm3wiZ0Ck+8=
github.com/second-state/WasmEdge-go v0.12.0/go.mod h1:HyBf9hVj1sRAjklsjc1Yvs9b5RcmthPG9z99dY78TKg=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down Expand Up @@ -873,12 +843,8 @@ go.etcd.io/etcd/client/v3 v3.5.4/go.mod h1:ZaRkVgBZC+L+dLCjTcF1hRXpgZXQPOvnA/Ak/
go.mongodb.org/mongo-driver v1.0.0/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/dig v1.16.1 h1:+alNIBsl0qfY0j6epRubp/9obgtrObRAc5aD+6jbWY8=
go.uber.org/dig v1.16.1/go.mod h1:557JTAUZT5bUK0SvCwikmLPPtdQhfvLYtO5tJgQSbnk=
go.uber.org/dig v1.17.0 h1:5Chju+tUvcC+N7N6EV08BJz41UZuO3BmHcN4A287ZLI=
go.uber.org/dig v1.17.0/go.mod h1:rTxpf7l5I0eBTlE6/9RL+lDybC7WFwY2QH55ZSjy1mU=
go.uber.org/fx v1.19.2 h1:SyFgYQFr1Wl0AYstE8vyYIzP4bFz2URrScjwC4cwUvY=
Expand Down Expand Up @@ -915,8 +881,6 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb h1:rhjz/8Mbfa8xROFiH+MQphmAmgqRM0bOMnytznhWEXk=
golang.org/x/exp v0.0.0-20230420155640-133eef4313cb/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o=
golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
7 changes: 3 additions & 4 deletions packages/chain/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,9 @@ func (cni *chainNodeImpl) run(ctx context.Context, cleanupFunc context.CancelFun
return
}
// needs to wait for state mgr and consensusInst
if cni.shutdownCoordinator.CheckNestedDone() {
cni.shutdownCoordinator.Done()
return
}
cni.shutdownCoordinator.WaitNestedWithLogging(1 * time.Second)
cni.shutdownCoordinator.Done()
return
}
select {
case txPublishResult, ok := <-recvTxPublishedPipeOutCh:
Expand Down
9 changes: 4 additions & 5 deletions packages/chain/statemanager/state_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,10 @@ func (smT *stateManager) run() { //nolint:gocyclo
return
}
// TODO what should the statemgr wait for?
if smT.shutdownCoordinator.CheckNestedDone() {
smT.log.Debugf("Stopping state manager, because context was closed")
smT.shutdownCoordinator.Done()
return
}
smT.shutdownCoordinator.WaitNestedWithLogging(1 * time.Second)
smT.log.Debugf("Stopping state manager, because context was closed")
smT.shutdownCoordinator.Done()
return
}
select {
case input, ok := <-inputPipeCh:
Expand Down
9 changes: 8 additions & 1 deletion packages/chains/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Chains struct {
consensusStateRegistry cmt_log.ConsensusStateRegistry
chainListener chain.ChainListener

mutex sync.RWMutex
mutex *sync.RWMutex
allChains *shrinkingmap.ShrinkingMap[isc.ChainID, *activeChain]
accessMgr access_mgr.AccessMgr

Expand Down Expand Up @@ -105,6 +105,7 @@ func New(
) *Chains {
ret := &Chains{
log: log,
mutex: &sync.RWMutex{},
allChains: shrinkingmap.New[isc.ChainID, *activeChain](),
nodeConnection: nodeConnection,
processorConfig: processorConfig,
Expand Down Expand Up @@ -161,6 +162,8 @@ func (c *Chains) Run(ctx context.Context) error {

func (c *Chains) Close() {
util.ExecuteIfNotNil(c.cleanupFunc)
c.mutex.RLock()
defer c.mutex.RUnlock()
c.allChains.ForEach(func(_ isc.ChainID, ac *activeChain) bool {
ac.cancelFunc()
return true
Expand Down Expand Up @@ -212,6 +215,10 @@ func (c *Chains) activateWithoutLocking(chainID isc.ChainID) error {
if c.ctx == nil {
return errors.New("run chains first")
}
if c.ctx.Err() != nil {
return errors.New("node is shutting down")
}

//
// Check, maybe it is already running.
if c.allChains.Has(chainID) {
Expand Down
23 changes: 23 additions & 0 deletions packages/nodeconn/nc_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,29 @@ func (ncc *ncChain) postTxLoop(ctx context.Context) {
ctxAttachWithTimeout, cancelCtxAttachWithTimeout := context.WithTimeout(ctxAttach, inxTimeoutPublishTransaction)
defer cancelCtxAttachWithTimeout()

// check if the context is already canceled before posting the transaction
if ctxAttachWithTimeout.Err() != nil {
// check if the transaction was already included (race condition with other validators)
checkTransactionIncludedAndSetConfirmed(pendingTx)

ncc.LogDebugf("posting transaction %s (chainID: %s, isReattachment: %t%s) failed. Context is already canceled. (ncc.ctx: %t, ctxConfirmed: %t, ctxPublished: %t, ctxAttach: %t, ctxAttachWithTimeout: %t, ",
pendingTx.ID().ToHex(),
ncc.chainID,
isReattachment,
debugInfoChaining,
ncc.ctx.Err() != nil,
pendingTx.ctxConfirmed.Err() != nil,
pendingTx.ctxPublished.Err() != nil,
ctxAttach.Err() != nil,
ctxAttachWithTimeout.Err() != nil,
)

// we always return nil here, even if the context was canceled by L1 confirmation,
// chain consensus, shutdown signal or chain deactivation.
// the actual reason is checked on caller site.
return nil
}

// post the transaction
blockID, err := nodeConn.doPostTx(ctxAttachWithTimeout, pendingTx.transaction, chainedTxBlockIDs...)
if err != nil && !errors.Is(err, context.Canceled) {
Expand Down
13 changes: 8 additions & 5 deletions packages/shutdown/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Coordinator struct {
parent *Coordinator
nestedWG *sync.WaitGroup
nestedLock *sync.RWMutex
nested *shrinkingmap.ShrinkingMap[string, struct{}]
nested *shrinkingmap.ShrinkingMap[string, *Coordinator]
log *logger.Logger
}

Expand All @@ -36,7 +36,7 @@ func newCoordinator(name string, parent *Coordinator, log *logger.Logger) *Coord
parent: parent,
nestedWG: &sync.WaitGroup{},
nestedLock: &sync.RWMutex{},
nested: shrinkingmap.New[string, struct{}](),
nested: shrinkingmap.New[string, *Coordinator](),
log: log,
}
}
Expand All @@ -45,11 +45,14 @@ func newCoordinator(name string, parent *Coordinator, log *logger.Logger) *Coord
func (s *Coordinator) Nested(name string) *Coordinator {
s.nestedLock.Lock()
defer s.nestedLock.Unlock()
if s.nested.Has(name) {
panic(fmt.Errorf("nested context '%v' already exist at %v", name, s.path))

if nested, exists := s.nested.Get(name); exists {
if !nested.CheckNestedDone() {
panic(fmt.Errorf("nested context '%v' already exist at %v", name, s.path))
}
}
newSub := newCoordinator(name, s, s.log)
s.nested.Set(name, struct{}{})
s.nested.Set(name, newSub)
s.nestedWG.Add(1)
return newSub
}
Expand Down
29 changes: 29 additions & 0 deletions scripts/run_tests_cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
CURRENT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
PARENT_DIR="$( builtin cd ${CURRENT_DIR}/.. >/dev/null 2>&1 ; pwd -P )"
cd ${PARENT_DIR}

OUTPUT_TO_FILE=false
if [[ $1 = "-f" ]]; then
OUTPUT_TO_FILE=true
fi

# check if richgo can be used to print colorful outputs
GO_EXECUTABLE=go
if [ "$OUTPUT_TO_FILE" = false ] && [ -x "$(command -v richgo)" ]; then
GO_EXECUTABLE=richgo
fi

FILES=$(go list ./tools/cluster/... | grep -v github.com/iotaledger/wasp/contracts/wasm)
${GO_EXECUTABLE} clean -testcache

make wasm
make install

if [ "$OUTPUT_TO_FILE" = false ]; then
${GO_EXECUTABLE} test -p 1 -failfast -count=1 -timeout=90m ${FILES}
else
${GO_EXECUTABLE} test -p 1 -failfast -count=1 -timeout=90m -v ${FILES} 2>&1 | tee tests_output.log
fi

cd ${CURRENT_DIR}
67 changes: 67 additions & 0 deletions tools/cluster/tests/cluster_testutils.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package tests

import (
"context"
"crypto/ecdsa"
"runtime/debug"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/samber/lo"
"github.com/stretchr/testify/require"

"github.com/iotaledger/wasp/clients/apiclient"
"github.com/iotaledger/wasp/clients/apiextensions"
"github.com/iotaledger/wasp/contracts/native/inccounter"
"github.com/iotaledger/wasp/packages/isc"
"github.com/iotaledger/wasp/packages/kv/codec"
"github.com/iotaledger/wasp/packages/vm/core/root"
)

Expand Down Expand Up @@ -80,3 +86,64 @@ func (e *ChainEnv) deployNativeIncCounterSC(initCounter ...int) {
_, err = e.Chain.CommitteeMultiClient().WaitUntilAllRequestsProcessedSuccessfully(e.Chain.ChainID, tx, false, 10*time.Second)
require.NoError(e.t, err)
}

func (e *ChainEnv) expectCounter(hname isc.Hname, counter int64) {
c := e.getNativeContractCounter(hname)
require.EqualValues(e.t, counter, c)
}

func (e *ChainEnv) getNativeContractCounter(hname isc.Hname) int64 {
return e.getCounterForNode(hname, 0)
}

func (e *ChainEnv) getCounterForNode(hname isc.Hname, nodeIndex int) int64 {
result, _, err := e.Chain.Cluster.WaspClient(nodeIndex).ChainsApi.
CallView(context.Background(), e.Chain.ChainID.String()).
ContractCallViewRequest(apiclient.ContractCallViewRequest{
ContractHName: hname.String(),
FunctionName: "getCounter",
}).Execute()
require.NoError(e.t, err)

decodedDict, err := apiextensions.APIJsonDictToDict(*result)
require.NoError(e.t, err)

counter, err := codec.DecodeInt64(decodedDict.Get(inccounter.VarCounter), 0)
require.NoError(e.t, err)

return counter
}

func (e *ChainEnv) waitUntilCounterEquals(hname isc.Hname, expected int64, duration time.Duration) {
timeout := time.After(duration)
var c int64
allNodesEqualFun := func() bool {
for _, node := range e.Chain.AllPeers {
c = e.getCounterForNode(hname, node)
if c != expected {
return false
}
}
return true
}
for {
select {
case <-timeout:
e.t.Errorf("timeout waiting for inccounter, current: %d, expected: %d", c, expected)
e.t.Fatal()
default:
if allNodesEqualFun() {
return // success
}
}
time.Sleep(1 * time.Second)
}
}

func newEthereumAccount() (*ecdsa.PrivateKey, common.Address) {
key, err := crypto.GenerateKey()
if err != nil {
panic(err)
}
return key, crypto.PubkeyToAddress(key.PublicKey)
}
9 changes: 0 additions & 9 deletions tools/cluster/tests/evm_jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -77,14 +76,6 @@ func newClusterTestEnv(t *testing.T, env *ChainEnv, nodeIndex int) *clusterTestE
return e
}

func newEthereumAccount() (*ecdsa.PrivateKey, common.Address) {
key, err := crypto.GenerateKey()
if err != nil {
panic(err)
}
return key, crypto.PubkeyToAddress(key.PublicKey)
}

const transferAllowanceToGasBudgetBaseTokens = 1 * isc.Million

func (e *clusterTestEnv) newEthereumAccountWithL2Funds(baseTokens ...uint64) (*ecdsa.PrivateKey, common.Address) {
Expand Down
Loading

0 comments on commit 5e7b5a6

Please sign in to comment.