mirror of https://github.com/poanetwork/gecko.git
merged bootstrapping improvements
This commit is contained in:
commit
fabd7cc82e
|
@ -30,9 +30,16 @@ type bootstrapper struct {
|
||||||
metrics
|
metrics
|
||||||
common.Bootstrapper
|
common.Bootstrapper
|
||||||
|
|
||||||
|
// IDs of vertices that we're already in the process of getting
|
||||||
|
// TODO: Find a better way to track; this keeps every single vertex's ID in memory when bootstrapping from nothing
|
||||||
|
seen ids.Set
|
||||||
|
|
||||||
|
numFetched uint64 // number of vertices that have been fetched from validators
|
||||||
|
|
||||||
// vtxReqs prevents asking validators for the same vertex
|
// vtxReqs prevents asking validators for the same vertex
|
||||||
vtxReqs common.Requests
|
vtxReqs common.Requests
|
||||||
|
|
||||||
|
// IDs of vertices that we have requested from other validators but haven't received
|
||||||
pending ids.Set
|
pending ids.Set
|
||||||
finished bool
|
finished bool
|
||||||
onFinished func()
|
onFinished func()
|
||||||
|
@ -91,8 +98,6 @@ func (b *bootstrapper) ForceAccepted(acceptedContainerIDs ids.Set) {
|
||||||
|
|
||||||
// Put ...
|
// Put ...
|
||||||
func (b *bootstrapper) Put(vdr ids.ShortID, requestID uint32, vtxID ids.ID, vtxBytes []byte) {
|
func (b *bootstrapper) Put(vdr ids.ShortID, requestID uint32, vtxID ids.ID, vtxBytes []byte) {
|
||||||
b.BootstrapConfig.Context.Log.Verbo("Put called for vertexID %s", vtxID)
|
|
||||||
|
|
||||||
vtx, err := b.State.ParseVertex(vtxBytes)
|
vtx, err := b.State.ParseVertex(vtxBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.BootstrapConfig.Context.Log.Debug("ParseVertex failed due to %s for block:\n%s",
|
b.BootstrapConfig.Context.Log.Debug("ParseVertex failed due to %s for block:\n%s",
|
||||||
|
@ -168,6 +173,10 @@ func (b *bootstrapper) addVertex(vtx avalanche.Vertex) {
|
||||||
|
|
||||||
func (b *bootstrapper) storeVertex(vtx avalanche.Vertex) {
|
func (b *bootstrapper) storeVertex(vtx avalanche.Vertex) {
|
||||||
vts := []avalanche.Vertex{vtx}
|
vts := []avalanche.Vertex{vtx}
|
||||||
|
b.numFetched++
|
||||||
|
if b.numFetched%2500 == 0 { // perioidcally inform user of progress
|
||||||
|
b.BootstrapConfig.Context.Log.Info("bootstrapping has fetched %d vertices", b.numFetched)
|
||||||
|
}
|
||||||
|
|
||||||
for len(vts) > 0 {
|
for len(vts) > 0 {
|
||||||
newLen := len(vts) - 1
|
newLen := len(vts) - 1
|
||||||
|
@ -187,6 +196,8 @@ func (b *bootstrapper) storeVertex(vtx avalanche.Vertex) {
|
||||||
vtx: vtx,
|
vtx: vtx,
|
||||||
}); err == nil {
|
}); err == nil {
|
||||||
b.numBlockedVtx.Inc()
|
b.numBlockedVtx.Inc()
|
||||||
|
} else {
|
||||||
|
b.BootstrapConfig.Context.Log.Verbo("couldn't push to vtxBlocked")
|
||||||
}
|
}
|
||||||
for _, tx := range vtx.Txs() {
|
for _, tx := range vtx.Txs() {
|
||||||
if err := b.TxBlocked.Push(&txJob{
|
if err := b.TxBlocked.Push(&txJob{
|
||||||
|
@ -195,10 +206,16 @@ func (b *bootstrapper) storeVertex(vtx avalanche.Vertex) {
|
||||||
tx: tx,
|
tx: tx,
|
||||||
}); err == nil {
|
}); err == nil {
|
||||||
b.numBlockedTx.Inc()
|
b.numBlockedTx.Inc()
|
||||||
|
} else {
|
||||||
|
b.BootstrapConfig.Context.Log.Verbo("couldn't push to txBlocked")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, parent := range vtx.Parents() {
|
||||||
|
if parentID := parent.ID(); !b.seen.Contains(parentID) {
|
||||||
|
b.seen.Add(parentID)
|
||||||
|
vts = append(vts, parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vts = append(vts, vtx.Parents()...)
|
|
||||||
case choices.Accepted:
|
case choices.Accepted:
|
||||||
b.BootstrapConfig.Context.Log.Verbo("Bootstrapping confirmed %s", vtxID)
|
b.BootstrapConfig.Context.Log.Verbo("Bootstrapping confirmed %s", vtxID)
|
||||||
case choices.Rejected:
|
case choices.Rejected:
|
||||||
|
@ -214,12 +231,14 @@ func (b *bootstrapper) finish() {
|
||||||
if b.finished {
|
if b.finished {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
b.BootstrapConfig.Context.Log.Info("bootstrapping finished fetching vertices. executing state transitions...")
|
||||||
|
|
||||||
b.executeAll(b.TxBlocked, b.numBlockedTx)
|
b.executeAll(b.TxBlocked, b.numBlockedTx)
|
||||||
b.executeAll(b.VtxBlocked, b.numBlockedVtx)
|
b.executeAll(b.VtxBlocked, b.numBlockedVtx)
|
||||||
|
|
||||||
// Start consensus
|
// Start consensus
|
||||||
b.onFinished()
|
b.onFinished()
|
||||||
|
b.seen = ids.Set{}
|
||||||
b.finished = true
|
b.finished = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue