events: Fix tipSetCache at higher heights
This commit is contained in:
parent
2874022251
commit
ba0559ae58
@ -64,8 +64,7 @@ func (e *heightEvents) headChangeAt(rev, app []*types.TipSet) error {
|
||||
}
|
||||
|
||||
if err := hnd.handle(incTs, ts.Height()); err != nil {
|
||||
msgInfo := ""
|
||||
log.Errorf("chain trigger (%s@H %d, called @ %d) failed: %s", msgInfo, triggerH, ts.Height(), err)
|
||||
log.Errorf("chain trigger (@H %d, called @ %d) failed: %s", triggerH, ts.Height(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ func (tsc *tipSetCache) add(ts *types.TipSet) error {
|
||||
}
|
||||
}
|
||||
|
||||
tsc.start = (tsc.start + 1) % len(tsc.cache)
|
||||
tsc.start = normalModulo(tsc.start+1, len(tsc.cache))
|
||||
tsc.cache[tsc.start] = ts
|
||||
if tsc.len < len(tsc.cache) {
|
||||
tsc.len++
|
||||
@ -54,7 +54,7 @@ func (tsc *tipSetCache) revert(ts *types.TipSet) error {
|
||||
}
|
||||
|
||||
tsc.cache[tsc.start] = nil
|
||||
tsc.start = (tsc.start - 1) % len(tsc.cache)
|
||||
tsc.start = normalModulo(tsc.start-1, len(tsc.cache))
|
||||
tsc.len--
|
||||
return nil
|
||||
}
|
||||
@ -71,15 +71,20 @@ func (tsc *tipSetCache) get(height uint64) (*types.TipSet, error) {
|
||||
}
|
||||
|
||||
clen := len(tsc.cache)
|
||||
tailH := tsc.cache[((tsc.start-tsc.len+1)%clen+clen)%clen].Height()
|
||||
tailH := tsc.cache[normalModulo(tsc.start-tsc.len+1, clen)].Height()
|
||||
|
||||
if height < tailH {
|
||||
log.Warnf("tipSetCache.get: requested tipset not in cache, requesting from storage (h=%d; tail=%d)", height, tailH)
|
||||
return tsc.storage(context.TODO(), height, tsc.cache[tailH])
|
||||
}
|
||||
|
||||
return tsc.cache[(int(height-tailH+1)%clen+clen)%clen], nil
|
||||
return tsc.cache[normalModulo(tsc.start-int(headH-height), clen)], nil
|
||||
}
|
||||
|
||||
func (tsc *tipSetCache) best() *types.TipSet {
|
||||
return tsc.cache[tsc.start]
|
||||
}
|
||||
|
||||
func normalModulo(n, m int) int {
|
||||
return (n%m + m) % m
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ func (m *Miner) scheduleNextPost(ppe uint64) {
|
||||
m.schedPost = ppe
|
||||
m.schedLk.Unlock()
|
||||
|
||||
log.Infof("Scheduling post at height %d", ppe-build.PoSTChallangeTime)
|
||||
log.Infof("Scheduling post at height %d (head=%d; ppe=%d, period=%d)", ppe-build.PoSTChallangeTime, ts.Height(), ppe, provingPeriod)
|
||||
err = m.events.ChainAt(m.computePost(ppe), func(ts *types.TipSet) error { // Revert
|
||||
// TODO: Cancel post
|
||||
log.Errorf("TODO: Cancel PoSt, re-run")
|
||||
@ -108,7 +108,7 @@ func (m *Miner) computePost(ppe uint64) func(ts *types.TipSet, curH uint64) erro
|
||||
|
||||
r, err := m.api.ChainGetRandomness(ctx, ts, nil, int(int64(ts.Height())-int64(ppe)+int64(build.PoSTChallangeTime))) // TODO: review: check math
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to get chain randomness for post: %w", err)
|
||||
return xerrors.Errorf("failed to get chain randomness for post (ts=%d; ppe=%d): %w", ts.Height(), ppe, err)
|
||||
}
|
||||
|
||||
log.Infof("running PoSt computation, rh=%d r=%s, ppe=%d, h=%d", int64(ts.Height())-int64(ppe)+int64(build.PoSTChallangeTime), base64.StdEncoding.EncodeToString(r), ppe, ts.Height())
|
||||
@ -147,7 +147,7 @@ func (m *Miner) computePost(ppe uint64) func(ts *types.TipSet, curH uint64) erro
|
||||
return xerrors.Errorf("pushing message to mpool: %w", err)
|
||||
}
|
||||
|
||||
log.Info("Waiting for post %s to appear on chain", smsg.Cid())
|
||||
log.Infof("Waiting for post %s to appear on chain", smsg.Cid())
|
||||
|
||||
// make sure it succeeds...
|
||||
rec, err := m.api.ChainWaitMsg(ctx, smsg.Cid())
|
||||
|
Loading…
Reference in New Issue
Block a user