diff --git a/chains/manager.go b/chains/manager.go index 78470b4..2751250 100644 --- a/chains/manager.go +++ b/chains/manager.go @@ -76,6 +76,9 @@ type Manager interface { // Add an alias to a chain Alias(ids.ID, string) error + // Returns true iff the chain with the given ID exists and is finished bootstrapping + IsBootstrapped(ids.ID) bool + Shutdown() } @@ -114,6 +117,10 @@ type manager struct { keystore *keystore.Keystore sharedMemory *atomic.SharedMemory + // Key: Chain's ID + // Value: The chain + chains map[[32]byte]common.Engine + unblocked bool blockedChains []ChainParameters } @@ -165,6 +172,7 @@ func New( server: server, keystore: keystore, sharedMemory: sharedMemory, + chains: make(map[[32]byte]common.Engine), } m.Initialize() return m @@ -454,7 +462,7 @@ func (m *manager) createAvalancheChain( eng: &engine, }) } - + m.chains[ctx.ChainID.Key()] = &engine return nil } @@ -546,9 +554,17 @@ func (m *manager) createSnowmanChain( eng: &engine, }) } + m.chains[ctx.ChainID.Key()] = &engine return nil } +func (m *manager) IsBootstrapped(id ids.ID) bool { + if chain, exists := m.chains[id.Key()]; exists && chain.IsBootstrapped() { + return true + } + return false +} + // Shutdown stops all the chains func (m *manager) Shutdown() { m.chainRouter.Shutdown() } diff --git a/snow/engine/avalanche/transitive.go b/snow/engine/avalanche/transitive.go index 7412276..de714c7 100644 --- a/snow/engine/avalanche/transitive.go +++ b/snow/engine/avalanche/transitive.go @@ -521,3 +521,8 @@ func (t *Transitive) sendRequest(vdr ids.ShortID, vtxID ids.ID) { t.numVtxRequests.Set(float64(t.vtxReqs.Len())) // Tracks performance statistics } + +// IsBootstrapped returns true iff this chain is done bootstrapping +func (t *Transitive) IsBootstrapped() bool { + return t.bootstrapped +} diff --git a/snow/engine/common/engine.go b/snow/engine/common/engine.go index 3be916d..7ca5622 100644 --- a/snow/engine/common/engine.go +++ b/snow/engine/common/engine.go @@ -14,6 +14,9 @@ type Engine interface { // Return the context of the chain this engine is working on Context() *snow.Context + + // Returns true iff the chain is done bootstrapping + IsBootstrapped() bool } // Handler defines the functions that are acted on the node diff --git a/snow/engine/common/test_engine.go b/snow/engine/common/test_engine.go index cf63df8..6e41dce 100644 --- a/snow/engine/common/test_engine.go +++ b/snow/engine/common/test_engine.go @@ -15,6 +15,7 @@ import ( type EngineTest struct { T *testing.T + Bootstrapped, CantStartup, CantGossip, CantShutdown, @@ -58,6 +59,8 @@ var _ Engine = &EngineTest{} // Default ... func (e *EngineTest) Default(cant bool) { + e.Bootstrapped = cant + e.CantStartup = cant e.CantGossip = cant e.CantShutdown = cant @@ -354,3 +357,8 @@ func (e *EngineTest) Chits(validatorID ids.ShortID, requestID uint32, containerI } return nil } + +// IsBootstrapped ... +func (e *EngineTest) IsBootstrapped() bool { + return e.Bootstrapped +} diff --git a/snow/engine/snowman/transitive.go b/snow/engine/snowman/transitive.go index ab4a881..6b57a8f 100644 --- a/snow/engine/snowman/transitive.go +++ b/snow/engine/snowman/transitive.go @@ -647,3 +647,8 @@ func (t *Transitive) deliver(blk snowman.Block) error { t.numBlockedBlk.Set(float64(t.pending.Len())) return t.errs.Err } + +// IsBootstrapped returns true iff this chain is done bootstrapping +func (t *Transitive) IsBootstrapped() bool { + return t.bootstrapped +}