Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat some opt #4574

Merged
merged 4 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/submodule/chain/chaininfo_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,19 @@ func (cia *chainInfoAPI) ChainExport(ctx context.Context, nroots abi.ChainEpoch,
return out, nil
}

// ChainGetPath returns a set of revert/apply operations needed to get from
// one tipset to another, for example:
//```
// to
// ^
// from tAA
// ^ ^
// tBA tAB
// ^---*--^
// ^
// tRR
//```
// Would return `[revert(tBA), apply(tAB), apply(tAA)]`
func (cia *chainInfoAPI) ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) ([]*chain.HeadChange, error) {
fts, err := cia.chain.ChainReader.GetTipSet(from)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ go 1.16

require (
contrib.go.opencensus.io/exporter/jaeger v0.2.1
contrib.go.opencensus.io/exporter/prometheus v0.3.0
contrib.go.opencensus.io/exporter/prometheus v0.4.0
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/Gurpartap/async v0.0.0-20180927173644-4f7f499dd9ee
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/awnumar/memguard v0.22.2
github.com/bluele/gcache v0.0.0-20190518031135-bc40bd653833
github.com/cskr/pubsub v1.0.2
github.com/detailyang/go-fallocate v0.0.0-20180908115635-432fa640bd2e
github.com/dgraph-io/badger/v2 v2.2007.2
github.com/docker/distribution v2.7.1+incompatible // indirect
Expand All @@ -32,7 +31,7 @@ require (
github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a
github.com/filecoin-project/go-jsonrpc v0.1.4-0.20210217175800-45ea43ac2bec
github.com/filecoin-project/go-leb128 v0.0.0-20190212224330-8d79a5489543
github.com/filecoin-project/go-paramfetch v0.0.2-0.20210614165157-25a6c7769498
github.com/filecoin-project/go-paramfetch v0.0.2
github.com/filecoin-project/go-state-types v0.1.1-0.20210915140513-d354ccf10379
github.com/filecoin-project/go-statestore v0.1.1 // indirect
github.com/filecoin-project/specs-actors v0.9.14
Expand Down Expand Up @@ -113,7 +112,6 @@ require (
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.26.0
github.com/raulk/clock v1.1.0
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
Expand All @@ -129,7 +127,7 @@ require (
go.opencensus.io v0.23.0
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.0.0-20210506145944-38f3c27a63bf
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6
golang.org/x/tools v0.1.1 // indirect
Expand Down
48 changes: 35 additions & 13 deletions go.sum

Large diffs are not rendered by default.

61 changes: 37 additions & 24 deletions pkg/chain/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/filecoin-project/go-state-types/network"
"github.com/filecoin-project/venus/pkg/state"

"github.com/cskr/pubsub"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
Expand All @@ -26,6 +25,7 @@ import (
carutil "github.com/ipld/go-car/util"
"github.com/pkg/errors"
cbg "github.com/whyrusleeping/cbor-gen"
"github.com/whyrusleeping/pubsub"
"go.opencensus.io/trace"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -334,25 +334,29 @@ func (store *Store) GetTipSet(key types.TipSetKey) (*types.TipSet, error) {
if key.IsEmpty() {
return store.GetHead(), nil
}
var blks []*types.BlockHeader

val, has := store.tsCache.Get(key)
if has {
return val.(*types.TipSet), nil
}

for _, id := range key.Cids() {
blk, err := store.GetBlock(context.TODO(), id)

cids := key.Cids()
blks := make([]*types.BlockHeader, len(cids))
for idx, c := range cids {
blk, err := store.GetBlock(context.TODO(), c)
if err != nil {
return nil, err
}
blks = append(blks, blk)

blks[idx] = blk
}

ts, err := types.NewTipSet(blks...)
if err != nil {
return nil, err
}
store.tsCache.Add(key, ts)

return ts, nil
}

Expand Down Expand Up @@ -548,7 +552,7 @@ func (store *Store) SetHead(ctx context.Context, newTS *types.TipSet) error {

//todo wrap by go function
Reverse(added)
Reverse(dropped)
//Reverse(dropped)

//do reorg
store.reorgCh <- reorg{
Expand All @@ -561,19 +565,20 @@ func (store *Store) SetHead(ctx context.Context, newTS *types.TipSet) error {
func (store *Store) reorgWorker(ctx context.Context) chan reorg {
headChangeNotifee := func(rev, app []*types.TipSet) error {
notif := make([]*HeadChange, len(rev)+len(app))
for i, apply := range rev {
for i, revert := range rev {
notif[i] = &HeadChange{
Type: HCRevert,
Val: apply,
Val: revert,
}
}

for i, revert := range app {
for i, apply := range app {
notif[i+len(rev)] = &HeadChange{
Type: HCApply,
Val: revert,
Val: apply,
}
}

// Publish an event that we have a new head.
store.headEvents.Pub(notif, HeadChangeTopic)
return nil
Expand Down Expand Up @@ -632,16 +637,17 @@ func (store *Store) reorgWorker(ctx context.Context) chan reorg {
// First message is guaranteed to be of len == 1, and type == 'current'.
// Then event in the message may be HCApply and HCRevert.
func (store *Store) SubHeadChanges(ctx context.Context) chan []*HeadChange {
out := make(chan []*HeadChange, 16)
store.mu.RLock()
subCh := store.headEvents.Sub(HeadChangeTopic)
head := store.head
store.mu.RUnlock()

out := make(chan []*HeadChange, 16)
out <- []*HeadChange{{
Type: HCCurrent,
Val: head,
}}

subCh := store.headEvents.Sub(HeadChangeTopic)
go func() {
defer close(out)
var unsubOnce sync.Once
Expand All @@ -653,12 +659,15 @@ func (store *Store) SubHeadChanges(ctx context.Context) chan []*HeadChange {
log.Warn("chain head sub exit loop")
return
}
if len(out) > 5 {
log.Warnf("head change sub is slow, has %d buffered entries", len(out))
}

select {
case out <- val.([]*HeadChange):
case <-ctx.Done():
default:
log.Errorf("closing head change subscription due to slow reader")
return
}
if len(out) > 5 {
log.Warnf("head change sub is slow, has %d buffered entries", len(out))
}
case <-ctx.Done():
unsubOnce.Do(func() {
Expand Down Expand Up @@ -1115,28 +1124,32 @@ func (store *Store) ReorgOps(a, b *types.TipSet) ([]*types.TipSet, []*types.TipS
return ReorgOps(store.GetTipSet, a, b)
}

// ReorgOps takes two tipsets (which can be at different heights), and walks
// their corresponding chains backwards one step at a time until we find
// a common ancestor. It then returns the respective chain segments that fork
// from the identified ancestor, in reverse order, where the first element of
// each slice is the supplied tipset, and the last element is the common
// ancestor.
//
// If an error happens along the way, we return the error with nil slices.
// todo should move this code into store.ReorgOps. anywhere use this function should invoke store.ReorgOps
func ReorgOps(lts func(types.TipSetKey) (*types.TipSet, error), a, b *types.TipSet) ([]*types.TipSet, []*types.TipSet, error) {
left := a
right := b

var leftChain, rightChain []*types.TipSet
for !left.Equals(right) {
lh := left.Height()
rh := right.Height()
if lh > rh {
if left.Height() > right.Height() {
leftChain = append(leftChain, left)
lKey := left.Parents()
par, err := lts(lKey)
par, err := lts(left.Parents())
if err != nil {
return nil, nil, err
}

left = par
} else {
rightChain = append(rightChain, right)
rKey := right.Parents()
par, err := lts(rKey)
par, err := lts(right.Parents())
if err != nil {
log.Infof("failed to fetch right.Parents: %s", err)
return nil, nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/chain/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ func TestRevertChange(t *testing.T) {
headChanges = <-ch
}
test.Equal(t, headChanges[0].Type, chain.HCRevert)
test.Equal(t, headChanges[0].Val, link1)
test.Equal(t, headChanges[0].Val, link3)
test.Equal(t, headChanges[1].Type, chain.HCRevert)
test.Equal(t, headChanges[1].Val, link2)
test.Equal(t, headChanges[2].Type, chain.HCRevert)
test.Equal(t, headChanges[2].Val, link3)
test.Equal(t, headChanges[2].Val, link1)

test.Equal(t, headChanges[3].Type, chain.HCApply)
test.Equal(t, headChanges[3].Val, link4)
Expand Down
11 changes: 5 additions & 6 deletions pkg/chainsync/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
blockstore "github.com/ipfs/go-ipfs-blockstore"
logging "github.com/ipfs/go-log/v2"
"github.com/pkg/errors"
"github.com/prometheus/common/log"
"go.opencensus.io/trace"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -151,9 +150,9 @@ func NewSyncer(fv StateProcessor,
fork fork.IFork) (*Syncer, error) {

if constants.InsecurePoStValidation {
log.Warn("*********************************************************************************************")
log.Warn(" [INSECURE-POST-VALIDATION] Insecure test validation is enabled. If you see this outside of a test, it is a severe bug! ")
log.Warn("*********************************************************************************************")
logSyncer.Warn("*********************************************************************************************")
logSyncer.Warn(" [INSECURE-POST-VALIDATION] Insecure test validation is enabled. If you see this outside of a test, it is a severe bug! ")
logSyncer.Warn("*********************************************************************************************")
}
return &Syncer{
exchangeClient: exchangeClient,
Expand Down Expand Up @@ -460,12 +459,12 @@ loop:
return chainTipsets, nil
}

log.Warnf("(fork detected) synced header chain")
logSyncer.Warnf("(fork detected) synced header chain")
fork, err := syncer.syncFork(ctx, base, knownTip)
if err != nil {
if xerrors.Is(err, ErrForkTooLong) {
// TODO: we're marking this block bad in the same way that we mark invalid blocks bad. Maybe distinguish?
log.Warn("adding forked chain to our bad tipset cache")
logSyncer.Warn("adding forked chain to our bad tipset cache")
/* for _, b := range incoming.Blocks() {
syncer.bad.Add(b.Cid(), NewBadBlockReason(incoming.Cids(), "fork past finality"))
}*/
Expand Down
30 changes: 16 additions & 14 deletions pkg/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ import (
"context"
"errors"
"fmt"
crypto2 "github.com/filecoin-project/venus/pkg/crypto"
"math"
stdbig "math/big"
"os"
"sort"
"sync"
"time"

"github.com/filecoin-project/venus/pkg/config"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/crypto"
"github.com/hashicorp/go-multierror"
lru "github.com/hashicorp/golang-lru"
"github.com/ipfs/go-cid"
Expand All @@ -27,19 +20,27 @@ import (
"github.com/ipfs/go-datastore/query"
logging "github.com/ipfs/go-log/v2"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/minio/blake2b-simd"
"github.com/raulk/clock"
lps "github.com/whyrusleeping/pubsub"
"golang.org/x/xerrors"

ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/crypto"

"github.com/filecoin-project/venus/pkg/chain"
"github.com/filecoin-project/venus/pkg/config"
"github.com/filecoin-project/venus/pkg/constants"
crypto2 "github.com/filecoin-project/venus/pkg/crypto"
"github.com/filecoin-project/venus/pkg/messagepool/journal"
"github.com/filecoin-project/venus/pkg/net/msgsub"
"github.com/filecoin-project/venus/pkg/repo"
"github.com/filecoin-project/venus/pkg/types"
"github.com/filecoin-project/venus/pkg/vm"
"github.com/filecoin-project/venus/pkg/vm/gas"

"github.com/raulk/clock"
)

type MpoolChange int
Expand Down Expand Up @@ -840,16 +841,17 @@ func (mp *MessagePool) Add(ctx context.Context, m *types.SignedMessage) error {
}

func sigCacheKey(m *types.SignedMessage) (string, error) {
c := m.Cid()
switch m.Signature.Type {
case crypto.SigTypeBLS:
if len(m.Signature.Data) < 90 {
return "", fmt.Errorf("bls signature too short")
if len(m.Signature.Data) != ffi.SignatureBytes {
return "", fmt.Errorf("bls signature incorrectly sized")
}

return string(c.Bytes()) + string(m.Signature.Data[64:]), nil
hashCache := blake2b.Sum256(append(m.Cid().Bytes(), m.Signature.Data...))

return string(hashCache[:]), nil
case crypto.SigTypeSecp256k1:
return string(c.Bytes()), nil
return string(m.Cid().Bytes()), nil
default:
return "", xerrors.Errorf("unrecognized signature type: %d", m.Signature.Type)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/paychmgr/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func (pm *Manager) trackInboundChannel(ctx context.Context, ch address.Address)
return pm.store.TrackChannel(stateCi)
}

// TODO: secret vs proof doesn't make sense, there is only one, not two
func (pm *Manager) SubmitVoucher(ctx context.Context, ch address.Address, sv *paych.SignedVoucher, secret []byte, proof []byte) (cid.Cid, error) {
if len(proof) > 0 {
return cid.Undef, errProofNotSupported
Expand Down
14 changes: 14 additions & 0 deletions pkg/paychmgr/paych.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@ func (ca *channelAccessor) checkVoucherValidUnlocked(ctx context.Context, ch add
return nil, xerrors.Errorf("voucher ChannelAddr doesn't match channel address, got %s, expected %s", sv.ChannelAddr, ch)
}

// check voucher is unlocked
if sv.Extra != nil {
return nil, xerrors.Errorf("voucher is Message Locked")
}
if sv.TimeLockMax != 0 {
return nil, xerrors.Errorf("voucher is Max Time Locked")
}
if sv.TimeLockMin != 0 {
return nil, xerrors.Errorf("voucher is Min Time Locked")
}
if len(sv.SecretPreimage) != 0 {
return nil, xerrors.Errorf("voucher is Hash Locked")
}

// Load payment channel actor state
act, pchState, err := ca.sa.loadPaychActorState(ctx, ch)
if err != nil {
Expand Down
Loading