Merge pull request #251 from filecoin-project/fix/events-crash
Event system fixes
This commit is contained in:
commit
1721c84ab5
@ -71,11 +71,11 @@ func (tsc *tipSetCache) get(height uint64) (*types.TipSet, error) {
|
||||
}
|
||||
|
||||
clen := len(tsc.cache)
|
||||
tailH := tsc.cache[normalModulo(tsc.start-tsc.len+1, clen)].Height()
|
||||
tail := tsc.cache[normalModulo(tsc.start-tsc.len+1, clen)]
|
||||
|
||||
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])
|
||||
if height < tail.Height() {
|
||||
log.Warnf("tipSetCache.get: requested tipset not in cache, requesting from storage (h=%d; tail=%d)", height, tail.Height())
|
||||
return tsc.storage(context.TODO(), height, tail)
|
||||
}
|
||||
|
||||
return tsc.cache[normalModulo(tsc.start-int(headH-height), clen)], nil
|
||||
@ -86,5 +86,5 @@ func (tsc *tipSetCache) best() *types.TipSet {
|
||||
}
|
||||
|
||||
func normalModulo(n, m int) int {
|
||||
return (n%m + m) % m
|
||||
return ((n % m) + m) % m
|
||||
}
|
||||
|
48
chain/events/tscache_test.go
Normal file
48
chain/events/tscache_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/filecoin-project/go-lotus/chain/types"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTsCache(t *testing.T) {
|
||||
tsc := newTSCache(50, func(context.Context, uint64, *types.TipSet) (*types.TipSet, error) {
|
||||
t.Fatal("storage call")
|
||||
return &types.TipSet{}, nil
|
||||
})
|
||||
|
||||
h := uint64(75)
|
||||
|
||||
add := func() {
|
||||
ts, err := types.NewTipSet([]*types.BlockHeader{{
|
||||
Height: h,
|
||||
StateRoot: dummyCid,
|
||||
Messages: dummyCid,
|
||||
MessageReceipts: dummyCid,
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := tsc.add(ts); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
h++
|
||||
}
|
||||
|
||||
for i := 0; i < 9000; i++ {
|
||||
fmt.Printf("i=%d; tl=%d; tcl=%d\n", i, tsc.len, len(tsc.cache))
|
||||
|
||||
if i%90 > 60 {
|
||||
if err := tsc.revert(tsc.best()); err != nil {
|
||||
t.Fatal(err, "; i:", i)
|
||||
return
|
||||
}
|
||||
h--
|
||||
} else {
|
||||
add()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -84,6 +84,11 @@ class Address extends React.Component {
|
||||
return info
|
||||
}
|
||||
|
||||
addColl = async () => {
|
||||
const coll = await this.props.client.call('Filecoin.StatePledgeCollateral', [null])
|
||||
this.props.addN(this.props.addr, coll)
|
||||
}
|
||||
|
||||
render() {
|
||||
let add20k = <span/>
|
||||
if(this.props.addN) {
|
||||
@ -91,6 +96,7 @@ class Address extends React.Component {
|
||||
if (this.props.add10k) {
|
||||
add20k = <span>{add20k} <a href="#" onClick={() => this.props.addN(this.props.addr, 2000000)}>[+2M]</a></span>
|
||||
add20k = <span>{add20k} <a href="#" onClick={() => this.props.addN(this.props.addr, 20000000)}>[+20M]</a></span>
|
||||
add20k = <span>{add20k} <a href="#" onClick={() => this.addColl()}>[<abbr title="min collateral">+C</abbr>]</a></span>
|
||||
}
|
||||
}
|
||||
let addr = truncAddr(this.props.addr, this.props.short ? 12 : 17)
|
||||
|
@ -39,7 +39,8 @@ func (m *Miner) beginPosting(ctx context.Context) {
|
||||
|
||||
// height needs to be +1, because otherwise we'd be trying to schedule PoSt
|
||||
// at current block height
|
||||
m.schedPost, _ = actors.ProvingPeriodEnd(ppe, ts.Height()+1)
|
||||
ppe, _ = actors.ProvingPeriodEnd(ppe, ts.Height()+1)
|
||||
m.schedPost = ppe
|
||||
|
||||
m.schedLk.Unlock()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user