From 56796ba87fcb27de3a31e2db70df019648da8d7a Mon Sep 17 00:00:00 2001 From: Felipe Madero Date: Wed, 13 Nov 2024 17:41:50 -0300 Subject: [PATCH] add wait for info.Bootstrapped to blockchain deploy --- local/blockchain.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/local/blockchain.go b/local/blockchain.go index 9d1f96a3..503cf77a 100644 --- a/local/blockchain.go +++ b/local/blockchain.go @@ -62,6 +62,8 @@ const ( subnetValidatorsWeight = 1000 // check period for blockchain logs while waiting for custom chains to be ready blockchainLogPullFrequency = time.Second + // check period for blockchain bootstrap status while waiting for custom chains to be ready + blockchainBootstrapCheckFrequency = time.Second // check period while waiting for all validators to be ready waitForValidatorsPullFrequency = time.Second defaultTimeout = time.Minute @@ -684,6 +686,7 @@ func (ln *localNetwork) waitForCustomChainsReady( return err } + // wait for blockchain to produce logs for _, nodeName := range nodeNames { node := ln.nodes[nodeName] if node.paused { @@ -716,6 +719,36 @@ func (ln *localNetwork) waitForCustomChainsReady( } } } + + // wait for info.isBootstrapped + // we need this check to be sure all APIs recognize the blockchain ID + for _, nodeName := range nodeNames { + node := ln.nodes[nodeName] + if node.paused { + continue + } + for { + boostrapped, err := node.client.InfoAPI().IsBootstrapped(ctx, chainInfo.blockchainID.String()) + if err != nil && !strings.Contains(err.Error(), "there is no chain with alias/ID") { + return err + } + if boostrapped { + break + } + ln.log.Info("not boostrapped, retrying...", + zap.String("subnet-ID", chainInfo.subnetID.String()), + zap.String("blockchain-ID", chainInfo.blockchainID.String()), + zap.String("node", node.name), + ) + select { + case <-ln.onStopCh: + return errAborted + case <-ctx.Done(): + return ctx.Err() + case <-time.After(blockchainBootstrapCheckFrequency): + } + } + } } ln.log.Info(logging.Green.Wrap("all custom chains are running!!!"))