add IsBootstrapped method to engine and chain manager

This commit is contained in:
Dan Laine 2020-06-24 16:49:11 -04:00
parent 4c75989056
commit c4605b2f2b
5 changed files with 38 additions and 1 deletions

View File

@ -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() }

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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
}