Skip to content

Commit

Permalink
Merge pull request #251 from filecoin-project/fix/events-crash
Browse files Browse the repository at this point in the history
Event system fixes
  • Loading branch information
magik6k committed Oct 1, 2019
2 parents 3c0c3d7 + 6ffa4b1 commit 1721c84
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
10 changes: 5 additions & 5 deletions chain/events/tscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 changes: 48 additions & 0 deletions chain/events/tscache_test.go
Original file line number Diff line number Diff line change
@@ -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()
}
}

}
6 changes: 6 additions & 0 deletions lotuspond/front/src/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,19 @@ 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) {
add20k = <span>&nbsp;<a href="#" onClick={() => this.props.addN(this.props.addr, 200000)}>[+200k]</a></span>
if (this.props.add10k) {
add20k = <span>{add20k}&nbsp;<a href="#" onClick={() => this.props.addN(this.props.addr, 2000000)}>[+2M]</a></span>
add20k = <span>{add20k}&nbsp;<a href="#" onClick={() => this.props.addN(this.props.addr, 20000000)}>[+20M]</a></span>
add20k = <span>{add20k}&nbsp;<a href="#" onClick={() => this.addColl()}>[<abbr title="min collateral">+C</abbr>]</a></span>
}
}
let addr = truncAddr(this.props.addr, this.props.short ? 12 : 17)
Expand Down
3 changes: 2 additions & 1 deletion storage/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 1721c84

Please sign in to comment.