mirror of https://github.com/poanetwork/gecko.git
add IsBootstrapped method to engine and chain manager
This commit is contained in:
parent
4c75989056
commit
c4605b2f2b
|
@ -76,6 +76,9 @@ type Manager interface {
|
||||||
// Add an alias to a chain
|
// Add an alias to a chain
|
||||||
Alias(ids.ID, string) error
|
Alias(ids.ID, string) error
|
||||||
|
|
||||||
|
// Returns true iff the chain with the given ID exists and is finished bootstrapping
|
||||||
|
IsBootstrapped(ids.ID) bool
|
||||||
|
|
||||||
Shutdown()
|
Shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +117,10 @@ type manager struct {
|
||||||
keystore *keystore.Keystore
|
keystore *keystore.Keystore
|
||||||
sharedMemory *atomic.SharedMemory
|
sharedMemory *atomic.SharedMemory
|
||||||
|
|
||||||
|
// Key: Chain's ID
|
||||||
|
// Value: The chain
|
||||||
|
chains map[[32]byte]common.Engine
|
||||||
|
|
||||||
unblocked bool
|
unblocked bool
|
||||||
blockedChains []ChainParameters
|
blockedChains []ChainParameters
|
||||||
}
|
}
|
||||||
|
@ -165,6 +172,7 @@ func New(
|
||||||
server: server,
|
server: server,
|
||||||
keystore: keystore,
|
keystore: keystore,
|
||||||
sharedMemory: sharedMemory,
|
sharedMemory: sharedMemory,
|
||||||
|
chains: make(map[[32]byte]common.Engine),
|
||||||
}
|
}
|
||||||
m.Initialize()
|
m.Initialize()
|
||||||
return m
|
return m
|
||||||
|
@ -454,7 +462,7 @@ func (m *manager) createAvalancheChain(
|
||||||
eng: &engine,
|
eng: &engine,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
m.chains[ctx.ChainID.Key()] = &engine
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,9 +554,17 @@ func (m *manager) createSnowmanChain(
|
||||||
eng: &engine,
|
eng: &engine,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
m.chains[ctx.ChainID.Key()] = &engine
|
||||||
return nil
|
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
|
// Shutdown stops all the chains
|
||||||
func (m *manager) Shutdown() { m.chainRouter.Shutdown() }
|
func (m *manager) Shutdown() { m.chainRouter.Shutdown() }
|
||||||
|
|
||||||
|
|
|
@ -521,3 +521,8 @@ func (t *Transitive) sendRequest(vdr ids.ShortID, vtxID ids.ID) {
|
||||||
|
|
||||||
t.numVtxRequests.Set(float64(t.vtxReqs.Len())) // Tracks performance statistics
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,9 @@ type Engine interface {
|
||||||
|
|
||||||
// Return the context of the chain this engine is working on
|
// Return the context of the chain this engine is working on
|
||||||
Context() *snow.Context
|
Context() *snow.Context
|
||||||
|
|
||||||
|
// Returns true iff the chain is done bootstrapping
|
||||||
|
IsBootstrapped() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler defines the functions that are acted on the node
|
// Handler defines the functions that are acted on the node
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
type EngineTest struct {
|
type EngineTest struct {
|
||||||
T *testing.T
|
T *testing.T
|
||||||
|
|
||||||
|
Bootstrapped,
|
||||||
CantStartup,
|
CantStartup,
|
||||||
CantGossip,
|
CantGossip,
|
||||||
CantShutdown,
|
CantShutdown,
|
||||||
|
@ -58,6 +59,8 @@ var _ Engine = &EngineTest{}
|
||||||
|
|
||||||
// Default ...
|
// Default ...
|
||||||
func (e *EngineTest) Default(cant bool) {
|
func (e *EngineTest) Default(cant bool) {
|
||||||
|
e.Bootstrapped = cant
|
||||||
|
|
||||||
e.CantStartup = cant
|
e.CantStartup = cant
|
||||||
e.CantGossip = cant
|
e.CantGossip = cant
|
||||||
e.CantShutdown = cant
|
e.CantShutdown = cant
|
||||||
|
@ -354,3 +357,8 @@ func (e *EngineTest) Chits(validatorID ids.ShortID, requestID uint32, containerI
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsBootstrapped ...
|
||||||
|
func (e *EngineTest) IsBootstrapped() bool {
|
||||||
|
return e.Bootstrapped
|
||||||
|
}
|
||||||
|
|
|
@ -647,3 +647,8 @@ func (t *Transitive) deliver(blk snowman.Block) error {
|
||||||
t.numBlockedBlk.Set(float64(t.pending.Len()))
|
t.numBlockedBlk.Set(float64(t.pending.Len()))
|
||||||
return t.errs.Err
|
return t.errs.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsBootstrapped returns true iff this chain is done bootstrapping
|
||||||
|
func (t *Transitive) IsBootstrapped() bool {
|
||||||
|
return t.bootstrapped
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue