Merge remote-tracking branch 'origin/testnet/3' into feat/4stage-seal
This commit is contained in:
commit
4e46d00eb6
@ -74,6 +74,7 @@ func TestDealFlow(t *testing.T, b APIBuilder, blocktime time.Duration) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmt.Println("Client data cid: ", fcid)
|
||||
deal, err := client.ClientStartDeal(ctx, fcid, addr, maddr, types.NewInt(1000000), 100)
|
||||
if err != nil {
|
||||
t.Fatalf("%+v", err)
|
||||
|
@ -8,6 +8,11 @@ import (
|
||||
|
||||
// Core network constants
|
||||
|
||||
const NetworkName = "interop"
|
||||
const BlocksTopic = "/fil/blocks/" + NetworkName
|
||||
const MessagesTopic = "/fil/msgs/" + NetworkName
|
||||
const DhtProtocolName = "/fil/kad/" + NetworkName
|
||||
|
||||
// /////
|
||||
// Storage
|
||||
|
||||
|
@ -45,8 +45,6 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
msgTopic = "/fil/messages"
|
||||
|
||||
localMsgsDs = "/mpool/local"
|
||||
|
||||
localUpdates = "update"
|
||||
@ -237,7 +235,7 @@ func (mp *MessagePool) repubLocal() {
|
||||
continue
|
||||
}
|
||||
|
||||
err = mp.api.PubSubPublish(msgTopic, msgb)
|
||||
err = mp.api.PubSubPublish(build.MessagesTopic, msgb)
|
||||
if err != nil {
|
||||
errout = multierr.Append(errout, xerrors.Errorf("could not publish: %w", err))
|
||||
continue
|
||||
@ -282,7 +280,7 @@ func (mp *MessagePool) Push(m *types.SignedMessage) (cid.Cid, error) {
|
||||
}
|
||||
mp.lk.Unlock()
|
||||
|
||||
return m.Cid(), mp.api.PubSubPublish(msgTopic, msgb)
|
||||
return m.Cid(), mp.api.PubSubPublish(build.MessagesTopic, msgb)
|
||||
}
|
||||
|
||||
func (mp *MessagePool) Add(m *types.SignedMessage) error {
|
||||
@ -480,7 +478,7 @@ func (mp *MessagePool) PushWithNonce(addr address.Address, cb func(uint64) (*typ
|
||||
log.Errorf("addLocal failed: %+v", err)
|
||||
}
|
||||
|
||||
return msg, mp.api.PubSubPublish(msgTopic, msgb)
|
||||
return msg, mp.api.PubSubPublish(build.MessagesTopic, msgb)
|
||||
}
|
||||
|
||||
func (mp *MessagePool) Remove(from address.Address, nonce uint64) {
|
||||
|
@ -3,6 +3,7 @@ package state
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
||||
|
||||
|
@ -115,51 +115,27 @@ func (sm *StateManager) TipSetState(ctx context.Context, ts *types.TipSet) (st c
|
||||
return st, rec, nil
|
||||
}
|
||||
|
||||
func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.BlockHeader, cb func(cid.Cid, *types.Message, *vm.ApplyRet) error) (cid.Cid, cid.Cid, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "computeTipSetState")
|
||||
defer span.End()
|
||||
type BlockMessages struct {
|
||||
Miner address.Address
|
||||
BlsMessages []store.ChainMsg
|
||||
SecpkMessages []store.ChainMsg
|
||||
}
|
||||
|
||||
for i := 0; i < len(blks); i++ {
|
||||
for j := i + 1; j < len(blks); j++ {
|
||||
if blks[i].Miner == blks[j].Miner {
|
||||
return cid.Undef, cid.Undef,
|
||||
xerrors.Errorf("duplicate miner in a tipset (%s %s)",
|
||||
blks[i].Miner, blks[j].Miner)
|
||||
}
|
||||
}
|
||||
}
|
||||
type ExecCallback func(cid.Cid, *types.Message, *vm.ApplyRet) error
|
||||
|
||||
pstate := blks[0].ParentStateRoot
|
||||
if len(blks[0].Parents) > 0 { // don't support forks on genesis
|
||||
parent, err := sm.cs.GetBlock(blks[0].Parents[0])
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("getting parent block: %w", err)
|
||||
}
|
||||
|
||||
pstate, err = sm.handleStateForks(ctx, blks[0].ParentStateRoot, blks[0].Height, parent.Height)
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("error handling state forks: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
cids := make([]cid.Cid, len(blks))
|
||||
for i, v := range blks {
|
||||
cids[i] = v.Cid()
|
||||
}
|
||||
|
||||
r := store.NewChainRand(sm.cs, cids, blks[0].Height)
|
||||
|
||||
vmi, err := sm.newVM(pstate, blks[0].Height, r, address.Undef, sm.cs.Blockstore(), sm.cs.VMSys())
|
||||
func (sm *StateManager) ApplyBlocks(ctx context.Context, pstate cid.Cid, bms []BlockMessages, epoch abi.ChainEpoch, r vm.Rand, cb ExecCallback) (cid.Cid, cid.Cid, error) {
|
||||
vmi, err := sm.newVM(pstate, epoch, r, address.Undef, sm.cs.Blockstore(), sm.cs.VMSys())
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("instantiating VM failed: %w", err)
|
||||
}
|
||||
|
||||
/*
|
||||
rewardActor, err := vmi.StateTree().GetActor(builtin.RewardActorAddr)
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
|
||||
}
|
||||
reward := vm.MiningReward(rewardActor.Balance)
|
||||
for _, b := range blks {
|
||||
for _, b := range bms {
|
||||
rewardActor, err = vmi.StateTree().GetActor(builtin.RewardActorAddr)
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get network actor: %w", err)
|
||||
@ -180,8 +156,8 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to deduct funds from network actor: %w", err)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: can't use method from chainstore because it doesnt let us know who the block miners were
|
||||
applied := make(map[address.Address]uint64)
|
||||
balances := make(map[address.Address]types.BigInt)
|
||||
|
||||
@ -199,21 +175,10 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
|
||||
}
|
||||
|
||||
var receipts []cbg.CBORMarshaler
|
||||
for _, b := range blks {
|
||||
for _, b := range bms {
|
||||
vmi.SetBlockMiner(b.Miner)
|
||||
|
||||
bms, sms, err := sm.cs.MessagesForBlock(b)
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get messages for block: %w", err)
|
||||
}
|
||||
|
||||
cmsgs := make([]store.ChainMsg, 0, len(bms)+len(sms))
|
||||
for _, m := range bms {
|
||||
cmsgs = append(cmsgs, m)
|
||||
}
|
||||
for _, sm := range sms {
|
||||
cmsgs = append(cmsgs, sm)
|
||||
}
|
||||
cmsgs := append(b.BlsMessages, b.SecpkMessages...)
|
||||
|
||||
for _, cm := range cmsgs {
|
||||
m := cm.VMMessage()
|
||||
@ -281,6 +246,68 @@ func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.Bl
|
||||
}
|
||||
|
||||
return st, rectroot, nil
|
||||
|
||||
}
|
||||
|
||||
func (sm *StateManager) computeTipSetState(ctx context.Context, blks []*types.BlockHeader, cb ExecCallback) (cid.Cid, cid.Cid, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "computeTipSetState")
|
||||
defer span.End()
|
||||
|
||||
for i := 0; i < len(blks); i++ {
|
||||
for j := i + 1; j < len(blks); j++ {
|
||||
if blks[i].Miner == blks[j].Miner {
|
||||
return cid.Undef, cid.Undef,
|
||||
xerrors.Errorf("duplicate miner in a tipset (%s %s)",
|
||||
blks[i].Miner, blks[j].Miner)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pstate := blks[0].ParentStateRoot
|
||||
if len(blks[0].Parents) > 0 { // don't support forks on genesis
|
||||
parent, err := sm.cs.GetBlock(blks[0].Parents[0])
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("getting parent block: %w", err)
|
||||
}
|
||||
|
||||
pstate, err = sm.handleStateForks(ctx, blks[0].ParentStateRoot, blks[0].Height, parent.Height)
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("error handling state forks: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
cids := make([]cid.Cid, len(blks))
|
||||
for i, v := range blks {
|
||||
cids[i] = v.Cid()
|
||||
}
|
||||
|
||||
r := store.NewChainRand(sm.cs, cids, blks[0].Height)
|
||||
|
||||
var blkmsgs []BlockMessages
|
||||
for _, b := range blks {
|
||||
bms, sms, err := sm.cs.MessagesForBlock(b)
|
||||
if err != nil {
|
||||
return cid.Undef, cid.Undef, xerrors.Errorf("failed to get messages for block: %w", err)
|
||||
}
|
||||
|
||||
bm := BlockMessages{
|
||||
Miner: b.Miner,
|
||||
BlsMessages: make([]store.ChainMsg, 0, len(bms)),
|
||||
SecpkMessages: make([]store.ChainMsg, 0, len(sms)),
|
||||
}
|
||||
|
||||
for _, m := range bms {
|
||||
bm.BlsMessages = append(bm.BlsMessages, m)
|
||||
}
|
||||
|
||||
for _, m := range sms {
|
||||
bm.SecpkMessages = append(bm.SecpkMessages, m)
|
||||
}
|
||||
|
||||
blkmsgs = append(blkmsgs, bm)
|
||||
}
|
||||
|
||||
return sm.ApplyBlocks(ctx, pstate, blkmsgs, abi.ChainEpoch(blks[0].Height), r, cb)
|
||||
}
|
||||
|
||||
func (sm *StateManager) parentState(ts *types.TipSet) cid.Cid {
|
||||
|
@ -6,7 +6,6 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/state"
|
||||
|
||||
amt "github.com/filecoin-project/go-amt-ipld/v2"
|
||||
commcid "github.com/filecoin-project/go-fil-commcid"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
@ -160,12 +159,6 @@ func GetSectorsForElectionPost(ctx context.Context, sm *StateManager, ts *types.
|
||||
|
||||
var uselessOtherArray []abi.SectorInfo
|
||||
for _, s := range sectors {
|
||||
cr, err := commcid.CIDToReplicaCommitmentV1(s.Info.Info.SealedCID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var uselessBuffer [32]byte
|
||||
copy(uselessBuffer[:], cr)
|
||||
uselessOtherArray = append(uselessOtherArray, abi.SectorInfo{
|
||||
RegisteredProof: s.Info.Info.RegisteredProof,
|
||||
SectorNumber: s.ID,
|
||||
@ -186,9 +179,34 @@ func GetMinerSectorSize(ctx context.Context, sm *StateManager, ts *types.TipSet,
|
||||
return mas.Info.SectorSize, nil
|
||||
}
|
||||
|
||||
func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (uint64, error) {
|
||||
log.Warn("stub GetMinerSlashed")
|
||||
return 0, nil
|
||||
func GetMinerSlashed(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) (bool, error) {
|
||||
var mas miner.State
|
||||
_, err := sm.LoadActorState(ctx, maddr, &mas, ts)
|
||||
if err != nil {
|
||||
return false, xerrors.Errorf("(get miner slashed) failed to load miner actor state")
|
||||
}
|
||||
|
||||
if mas.PoStState.HasFailedPost() {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
var spas power.State
|
||||
_, err = sm.LoadActorState(ctx, builtin.StoragePowerActorAddr, &spas, ts)
|
||||
if err != nil {
|
||||
return false, xerrors.Errorf("(get miner slashed) failed to load power actor state")
|
||||
}
|
||||
|
||||
store := sm.cs.Store(ctx)
|
||||
claims := adt.AsMap(store, spas.Claims)
|
||||
ok, err := claims.Get(power.AddrKey(maddr), nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !ok {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func GetMinerFaults(ctx context.Context, sm *StateManager, ts *types.TipSet, maddr address.Address) ([]abi.SectorNumber, error) {
|
||||
|
@ -523,13 +523,13 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) err
|
||||
}
|
||||
|
||||
winnerCheck := async.Err(func() error {
|
||||
slashedAt, err := stmgr.GetMinerSlashed(ctx, syncer.sm, baseTs, h.Miner)
|
||||
slashed, err := stmgr.GetMinerSlashed(ctx, syncer.sm, baseTs, h.Miner)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to check if block miner was slashed: %w", err)
|
||||
}
|
||||
|
||||
if slashedAt != 0 {
|
||||
return xerrors.Errorf("received block was from miner slashed at height %d", slashedAt)
|
||||
if slashed {
|
||||
return xerrors.Errorf("received block was from slashed or invalid miner")
|
||||
}
|
||||
|
||||
mpow, tpow, err := stmgr.GetPower(ctx, syncer.sm, baseTs, h.Miner)
|
||||
|
@ -5,10 +5,10 @@ package types
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
||||
"github.com/ipfs/go-cid"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
xerrors "golang.org/x/xerrors"
|
||||
@ -1020,10 +1020,16 @@ func (t *MessageReceipt) MarshalCBOR(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// t.ExitCode (uint8) (uint8)
|
||||
// t.ExitCode (exitcode.ExitCode) (int64)
|
||||
if t.ExitCode >= 0 {
|
||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.ExitCode))); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajNegativeInt, uint64(-t.ExitCode)-1)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// t.Return ([]uint8) (slice)
|
||||
if len(t.Return) > cbg.ByteArrayMaxLen {
|
||||
@ -1059,19 +1065,31 @@ func (t *MessageReceipt) UnmarshalCBOR(r io.Reader) error {
|
||||
return fmt.Errorf("cbor input had wrong number of fields")
|
||||
}
|
||||
|
||||
// t.ExitCode (uint8) (uint8)
|
||||
|
||||
maj, extra, err = cbg.CborReadHeader(br)
|
||||
// t.ExitCode (exitcode.ExitCode) (int64)
|
||||
{
|
||||
maj, extra, err := cbg.CborReadHeader(br)
|
||||
var extraI int64
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if maj != cbg.MajUnsignedInt {
|
||||
return fmt.Errorf("wrong type for uint8 field")
|
||||
switch maj {
|
||||
case cbg.MajUnsignedInt:
|
||||
extraI = int64(extra)
|
||||
if extraI < 0 {
|
||||
return fmt.Errorf("int64 positive overflow")
|
||||
}
|
||||
if extra > math.MaxUint8 {
|
||||
return fmt.Errorf("integer in input was too large for uint8 field")
|
||||
case cbg.MajNegativeInt:
|
||||
extraI = int64(extra)
|
||||
if extraI < 0 {
|
||||
return fmt.Errorf("int64 negative oveflow")
|
||||
}
|
||||
extraI = -1 - extraI
|
||||
default:
|
||||
return fmt.Errorf("wrong type for int64 field: %d", maj)
|
||||
}
|
||||
|
||||
t.ExitCode = exitcode.ExitCode(extraI)
|
||||
}
|
||||
t.ExitCode = uint8(extra)
|
||||
// t.Return ([]uint8) (slice)
|
||||
|
||||
maj, extra, err = cbg.CborReadHeader(br)
|
||||
|
@ -2,10 +2,12 @@ package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
||||
)
|
||||
|
||||
type MessageReceipt struct {
|
||||
ExitCode uint8
|
||||
ExitCode exitcode.ExitCode
|
||||
Return []byte
|
||||
GasUsed BigInt
|
||||
}
|
||||
|
@ -5,14 +5,16 @@ import (
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/go-sectorbuilder"
|
||||
|
||||
vchain "github.com/filecoin-project/chain-validation/pkg/chain"
|
||||
vstate "github.com/filecoin-project/chain-validation/pkg/state"
|
||||
vtypes "github.com/filecoin-project/chain-validation/pkg/state/types"
|
||||
vtypes "github.com/filecoin-project/chain-validation/chain/types"
|
||||
vstate "github.com/filecoin-project/chain-validation/state"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/vm"
|
||||
)
|
||||
@ -21,50 +23,111 @@ import (
|
||||
type Applier struct {
|
||||
}
|
||||
|
||||
var _ vchain.Applier = &Applier{}
|
||||
var _ vstate.Applier = &Applier{}
|
||||
|
||||
func NewApplier() *Applier {
|
||||
return &Applier{}
|
||||
}
|
||||
|
||||
func (a *Applier) ApplyMessage(eCtx *vchain.ExecutionContext, state vstate.Wrapper, message interface{}) (vchain.MessageReceipt, error) {
|
||||
func (a *Applier) ApplyMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWrapper, message *vtypes.Message) (vtypes.MessageReceipt, error) {
|
||||
ctx := context.TODO()
|
||||
st := state.(*StateWrapper)
|
||||
|
||||
base := st.Cid()
|
||||
base := st.Root()
|
||||
randSrc := &vmRand{eCtx}
|
||||
minerAddr, err := address.NewFromBytes(eCtx.MinerOwner.Bytes())
|
||||
lotusVM, err := vm.NewVM(base, abi.ChainEpoch(eCtx.Epoch), randSrc, eCtx.Miner, st.bs, vm.Syscalls(sectorbuilder.ProofVerifier))
|
||||
if err != nil {
|
||||
return vchain.MessageReceipt{}, err
|
||||
}
|
||||
lotusVM, err := vm.NewVM(base, abi.ChainEpoch(eCtx.Epoch), randSrc, minerAddr, st.bs, vm.Syscalls(sectorbuilder.ProofVerifier))
|
||||
if err != nil {
|
||||
return vchain.MessageReceipt{}, err
|
||||
return vtypes.MessageReceipt{}, err
|
||||
}
|
||||
|
||||
ret, err := lotusVM.ApplyMessage(ctx, message.(*types.Message))
|
||||
ret, err := lotusVM.ApplyMessage(ctx, toLotusMsg(message))
|
||||
if err != nil {
|
||||
return vchain.MessageReceipt{}, err
|
||||
return vtypes.MessageReceipt{}, err
|
||||
}
|
||||
|
||||
st.stateRoot, err = lotusVM.Flush(ctx)
|
||||
if err != nil {
|
||||
return vchain.MessageReceipt{}, err
|
||||
return vtypes.MessageReceipt{}, err
|
||||
}
|
||||
|
||||
mr := vchain.MessageReceipt{
|
||||
ExitCode: ret.ExitCode,
|
||||
mr := vtypes.MessageReceipt{
|
||||
ExitCode: exitcode.ExitCode(ret.ExitCode),
|
||||
ReturnValue: ret.Return,
|
||||
GasUsed: vtypes.GasUnit(ret.GasUsed.Uint64()),
|
||||
GasUsed: ret.GasUsed,
|
||||
}
|
||||
|
||||
return mr, ret.ActorErr
|
||||
return mr, nil
|
||||
}
|
||||
|
||||
func (a *Applier) ApplyTipSetMessages(state vstate.VMWrapper, blocks []vtypes.BlockMessagesInfo, epoch abi.ChainEpoch, rnd vstate.RandomnessSource) ([]vtypes.MessageReceipt, error) {
|
||||
sw := state.(*StateWrapper)
|
||||
cs := store.NewChainStore(sw.bs, sw.ds, nil)
|
||||
sm := stmgr.NewStateManager(cs)
|
||||
|
||||
var bms []stmgr.BlockMessages
|
||||
for _, b := range blocks {
|
||||
bm := stmgr.BlockMessages{
|
||||
Miner: b.Miner,
|
||||
}
|
||||
|
||||
for _, m := range b.BLSMessages {
|
||||
bm.BlsMessages = append(bm.BlsMessages, toLotusMsg(m))
|
||||
}
|
||||
|
||||
for _, m := range b.SECPMessages {
|
||||
bm.SecpkMessages = append(bm.SecpkMessages, toLotusMsg(&m.Message))
|
||||
}
|
||||
|
||||
bms = append(bms, bm)
|
||||
}
|
||||
|
||||
var receipts []vtypes.MessageReceipt
|
||||
sroot, _, err := sm.ApplyBlocks(context.TODO(), state.Root(), bms, epoch, &randWrapper{rnd}, func(c cid.Cid, msg *types.Message, ret *vm.ApplyRet) error {
|
||||
receipts = append(receipts, vtypes.MessageReceipt{
|
||||
ExitCode: exitcode.ExitCode(ret.ExitCode),
|
||||
ReturnValue: ret.Return,
|
||||
|
||||
GasUsed: ret.GasUsed,
|
||||
})
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
state.(*StateWrapper).stateRoot = sroot
|
||||
|
||||
return receipts, nil
|
||||
}
|
||||
|
||||
type randWrapper struct {
|
||||
rnd vstate.RandomnessSource
|
||||
}
|
||||
|
||||
func (w *randWrapper) GetRandomness(ctx context.Context, pers crypto.DomainSeparationTag, round int64, entropy []byte) ([]byte, error) {
|
||||
return w.rnd.Randomness(ctx, pers, abi.ChainEpoch(round), entropy)
|
||||
}
|
||||
|
||||
type vmRand struct {
|
||||
eCtx *vchain.ExecutionContext
|
||||
eCtx *vtypes.ExecutionContext
|
||||
}
|
||||
|
||||
func (*vmRand) GetRandomness(ctx context.Context, dst crypto.DomainSeparationTag, h int64, input []byte) ([]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func toLotusMsg(msg *vtypes.Message) *types.Message {
|
||||
return &types.Message{
|
||||
To: msg.To,
|
||||
From: msg.From,
|
||||
|
||||
Nonce: uint64(msg.CallSeqNum),
|
||||
Method: msg.Method,
|
||||
|
||||
Value: types.BigInt{msg.Value.Int},
|
||||
GasPrice: types.BigInt{msg.GasPrice.Int},
|
||||
GasLimit: types.NewInt(uint64(msg.GasLimit)),
|
||||
|
||||
Params: msg.Params,
|
||||
}
|
||||
}
|
||||
|
31
chain/validation/config.go
Normal file
31
chain/validation/config.go
Normal file
@ -0,0 +1,31 @@
|
||||
package validation
|
||||
|
||||
//
|
||||
// Config
|
||||
//
|
||||
|
||||
type Config struct {
|
||||
trackGas bool
|
||||
checkExitCode bool
|
||||
checkReturnValue bool
|
||||
}
|
||||
|
||||
func NewConfig(gas, exit, ret bool) *Config {
|
||||
return &Config{
|
||||
trackGas: gas,
|
||||
checkExitCode: exit,
|
||||
checkReturnValue: ret,
|
||||
}
|
||||
}
|
||||
|
||||
func (v Config) ValidateGas() bool {
|
||||
return v.trackGas
|
||||
}
|
||||
|
||||
func (v Config) ValidateExitCode() bool {
|
||||
return v.checkExitCode
|
||||
}
|
||||
|
||||
func (v Config) ValidateReturnValue() bool {
|
||||
return v.checkReturnValue
|
||||
}
|
@ -1,27 +1,47 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
vchain "github.com/filecoin-project/chain-validation/pkg/chain"
|
||||
vstate "github.com/filecoin-project/chain-validation/pkg/state"
|
||||
"github.com/filecoin-project/chain-validation/pkg/suites"
|
||||
"context"
|
||||
|
||||
vstate "github.com/filecoin-project/chain-validation/state"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
acrypto "github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
)
|
||||
|
||||
type factories struct {
|
||||
type Factories struct {
|
||||
*Applier
|
||||
}
|
||||
|
||||
var _ suites.Factories = &factories{}
|
||||
var _ vstate.Factories = &Factories{}
|
||||
|
||||
func NewFactories() *factories {
|
||||
func NewFactories() *Factories {
|
||||
applier := NewApplier()
|
||||
return &factories{applier}
|
||||
return &Factories{applier}
|
||||
}
|
||||
|
||||
func (f *factories) NewState() vstate.Wrapper {
|
||||
func (f *Factories) NewState() vstate.VMWrapper {
|
||||
return NewState()
|
||||
}
|
||||
|
||||
func (f *factories) NewMessageFactory(wrapper vstate.Wrapper) vchain.MessageFactory {
|
||||
signer := wrapper.(*StateWrapper).Signer()
|
||||
return NewMessageFactory(signer)
|
||||
func (f *Factories) NewKeyManager() vstate.KeyManager {
|
||||
return newKeyManager()
|
||||
}
|
||||
|
||||
type fakeRandSrc struct {
|
||||
}
|
||||
|
||||
func (r fakeRandSrc) Randomness(_ context.Context, _ acrypto.DomainSeparationTag, _ abi.ChainEpoch, _ []byte) (abi.Randomness, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (f *Factories) NewRandomnessSource() vstate.RandomnessSource {
|
||||
return &fakeRandSrc{}
|
||||
}
|
||||
|
||||
func (f *Factories) NewValidationConfig() vstate.ValidationConfig {
|
||||
trackGas := false
|
||||
checkExit := false
|
||||
checkRet := false
|
||||
// ignore gas and return value assertions
|
||||
return NewConfig(trackGas, checkExit, checkRet)
|
||||
}
|
||||
|
99
chain/validation/keymanager.go
Normal file
99
chain/validation/keymanager.go
Normal file
@ -0,0 +1,99 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-crypto"
|
||||
acrypto "github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
|
||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/wallet"
|
||||
)
|
||||
|
||||
type KeyManager struct {
|
||||
// Private keys by address
|
||||
keys map[address.Address]*wallet.Key
|
||||
|
||||
// Seed for deterministic secp key generation.
|
||||
secpSeed int64
|
||||
// Seed for deterministic bls key generation.
|
||||
blsSeed int64 // nolint: structcheck
|
||||
}
|
||||
|
||||
func newKeyManager() *KeyManager {
|
||||
return &KeyManager{
|
||||
keys: make(map[address.Address]*wallet.Key),
|
||||
secpSeed: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (k *KeyManager) NewSECP256k1AccountAddress() address.Address {
|
||||
secpKey := k.newSecp256k1Key()
|
||||
k.keys[secpKey.Address] = secpKey
|
||||
return secpKey.Address
|
||||
}
|
||||
|
||||
func (k *KeyManager) NewBLSAccountAddress() address.Address {
|
||||
blsKey := k.newBLSKey()
|
||||
k.keys[blsKey.Address] = blsKey
|
||||
return blsKey.Address
|
||||
}
|
||||
|
||||
func (k *KeyManager) Sign(addr address.Address, data []byte) (acrypto.Signature, error) {
|
||||
ki, ok := k.keys[addr]
|
||||
if !ok {
|
||||
return acrypto.Signature{}, fmt.Errorf("unknown address %v", addr)
|
||||
}
|
||||
sig, err := crypto.Sign(ki.PrivateKey, data)
|
||||
if err != nil {
|
||||
return acrypto.Signature{}, err
|
||||
}
|
||||
var sigType acrypto.SigType
|
||||
if ki.Type == wallet.KTBLS {
|
||||
sigType = acrypto.SigTypeBLS
|
||||
} else if ki.Type == wallet.KTSecp256k1 {
|
||||
sigType = acrypto.SigTypeSecp256k1
|
||||
} else {
|
||||
panic("unknown signature type")
|
||||
}
|
||||
return acrypto.Signature{
|
||||
Type: sigType,
|
||||
Data: sig,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func (k *KeyManager) newSecp256k1Key() *wallet.Key {
|
||||
randSrc := rand.New(rand.NewSource(k.secpSeed))
|
||||
prv, err := crypto.GenerateKeyFromSeed(randSrc)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
k.secpSeed++
|
||||
key, err := wallet.NewKey(types.KeyInfo{
|
||||
Type: wallet.KTSecp256k1,
|
||||
PrivateKey: prv,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
func (k *KeyManager) newBLSKey() *wallet.Key {
|
||||
// FIXME: bls needs deterministic key generation
|
||||
//sk := ffi.PrivateKeyGenerate(s.blsSeed)
|
||||
// s.blsSeed++
|
||||
sk := ffi.PrivateKeyGenerate()
|
||||
key, err := wallet.NewKey(types.KeyInfo{
|
||||
Type: wallet.KTBLS,
|
||||
PrivateKey: sk[:],
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return key
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ipfs/go-cid"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
vchain "github.com/filecoin-project/chain-validation/pkg/chain"
|
||||
vactors "github.com/filecoin-project/chain-validation/pkg/state/actors"
|
||||
vaddress "github.com/filecoin-project/chain-validation/pkg/state/address"
|
||||
vtypes "github.com/filecoin-project/chain-validation/pkg/state/types"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
type Signer interface {
|
||||
Sign(ctx context.Context, addr vaddress.Address, msg []byte) (*crypto.Signature, error)
|
||||
}
|
||||
|
||||
type MessageFactory struct {
|
||||
signer Signer
|
||||
}
|
||||
|
||||
var _ vchain.MessageFactory = &MessageFactory{}
|
||||
|
||||
func NewMessageFactory(signer Signer) *MessageFactory {
|
||||
return &MessageFactory{signer}
|
||||
}
|
||||
|
||||
func (mf *MessageFactory) MakeMessage(from, to vaddress.Address, method vchain.MethodID, nonce uint64, value, gasPrice vtypes.BigInt, gasLimit vtypes.GasUnit, params []byte) (interface{}, error) {
|
||||
fromDec, err := address.NewFromBytes(from.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
toDec, err := address.NewFromBytes(to.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
valueDec := types.BigInt{value.Int}
|
||||
|
||||
if int(method) >= len(methods) {
|
||||
return nil, xerrors.Errorf("No method name for method %v", method)
|
||||
}
|
||||
methodId := methods[method]
|
||||
msg := &types.Message{
|
||||
toDec,
|
||||
fromDec,
|
||||
nonce,
|
||||
valueDec,
|
||||
types.BigInt{gasPrice.Int},
|
||||
types.NewInt(uint64(gasLimit)),
|
||||
abi.MethodNum(methodId),
|
||||
params,
|
||||
}
|
||||
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
func (mf *MessageFactory) FromSingletonAddress(addr vactors.SingletonActorID) vaddress.Address {
|
||||
return fromSingletonAddress(addr)
|
||||
}
|
||||
|
||||
func (mf *MessageFactory) FromActorCodeCid(code vactors.ActorCodeID) cid.Cid {
|
||||
return fromActorCode(code)
|
||||
}
|
||||
|
||||
// Maps method enumeration values to method names.
|
||||
// This will change to a mapping to method ids when method dispatch is updated to use integers.
|
||||
var methods = []uint64{
|
||||
vchain.NoMethod: 0,
|
||||
vchain.InitExec: uint64(builtin.MethodsInit.Exec),
|
||||
|
||||
vchain.StoragePowerConstructor: uint64(builtin.MethodsPower.Constructor),
|
||||
vchain.StoragePowerCreateStorageMiner: uint64(builtin.MethodsPower.CreateMiner),
|
||||
|
||||
vchain.StorageMinerUpdatePeerID: 0, //actors.MAMethods.UpdatePeerID,
|
||||
vchain.StorageMinerGetOwner: 0, //actors.MAMethods.GetOwner,
|
||||
vchain.StorageMinerGetPower: 0, //actors.MAMethods.GetPower,
|
||||
vchain.StorageMinerGetWorkerAddr: 0, //actors.MAMethods.GetWorkerAddr,
|
||||
vchain.StorageMinerGetPeerID: 0, //actors.MAMethods.GetPeerID,
|
||||
vchain.StorageMinerGetSectorSize: 0, //actors.MAMethods.GetSectorSize,
|
||||
|
||||
vchain.MultiSigConstructor: uint64(builtin.MethodsMultisig.Constructor),
|
||||
vchain.MultiSigPropose: uint64(builtin.MethodsMultisig.Propose),
|
||||
vchain.MultiSigApprove: uint64(builtin.MethodsMultisig.Approve),
|
||||
vchain.MultiSigCancel: uint64(builtin.MethodsMultisig.Cancel),
|
||||
vchain.MultiSigClearCompleted: uint64(builtin.MethodsMultisig.ClearCompleted),
|
||||
vchain.MultiSigAddSigner: uint64(builtin.MethodsMultisig.AddSigner),
|
||||
vchain.MultiSigRemoveSigner: uint64(builtin.MethodsMultisig.RemoveSigner),
|
||||
vchain.MultiSigSwapSigner: uint64(builtin.MethodsMultisig.SwapSigner),
|
||||
vchain.MultiSigChangeRequirement: uint64(builtin.MethodsMultisig.ChangeNumApprovalsThreshold),
|
||||
// More to follow...
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
vchain "github.com/filecoin-project/chain-validation/pkg/chain"
|
||||
vactors "github.com/filecoin-project/chain-validation/pkg/state/actors"
|
||||
vaddress "github.com/filecoin-project/chain-validation/pkg/state/address"
|
||||
vtypes "github.com/filecoin-project/chain-validation/pkg/state/types"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/wallet"
|
||||
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
||||
)
|
||||
|
||||
func TestMessageFactory(t *testing.T) {
|
||||
ks := wallet.NewMemKeyStore()
|
||||
wallet, err := wallet.NewWallet(ks)
|
||||
require.NoError(t, err)
|
||||
factory := NewMessageFactory(&walletWrapper{wallet})
|
||||
|
||||
gasPrice := vtypes.NewInt(1)
|
||||
gasLimit := vtypes.GasUnit(1000)
|
||||
p := vchain.NewMessageProducer(factory, gasLimit, gasPrice)
|
||||
|
||||
sender, err := wallet.GenerateKey(types.KTSecp256k1)
|
||||
require.NoError(t, err)
|
||||
|
||||
bfAddr := factory.FromSingletonAddress(vactors.BurntFundsAddress)
|
||||
addr, err := vaddress.NewFromBytes(sender.Bytes())
|
||||
require.NoError(t, err)
|
||||
m, err := p.Transfer(addr, bfAddr, 0, 1)
|
||||
require.NoError(t, err)
|
||||
|
||||
messages := p.Messages()
|
||||
assert.Equal(t, 1, len(messages))
|
||||
msg := m.(*types.Message)
|
||||
assert.Equal(t, m, msg)
|
||||
assert.Equal(t, sender, msg.From)
|
||||
assert.Equal(t, actors.BurntFundsAddress, msg.To)
|
||||
assert.Equal(t, types.NewInt(1), msg.Value)
|
||||
}
|
||||
|
||||
type walletWrapper struct {
|
||||
w *wallet.Wallet
|
||||
}
|
||||
|
||||
func (ww *walletWrapper) Sign(ctx context.Context, vaddr vaddress.Address, msg []byte) (*types.Signature, error) {
|
||||
addr, err := address.NewFromBytes(vaddr.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ww.w.Sign(ctx, addr, msg)
|
||||
}
|
@ -2,51 +2,241 @@ package validation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-datastore"
|
||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
cbor "github.com/ipfs/go-ipld-cbor"
|
||||
"github.com/minio/blake2b-simd"
|
||||
cbg "github.com/whyrusleeping/cbor-gen"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
vstate "github.com/filecoin-project/chain-validation/pkg/state"
|
||||
vactors "github.com/filecoin-project/chain-validation/pkg/state/actors"
|
||||
vaddress "github.com/filecoin-project/chain-validation/pkg/state/address"
|
||||
vtypes "github.com/filecoin-project/chain-validation/pkg/state/types"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/go-crypto"
|
||||
vstate "github.com/filecoin-project/chain-validation/state"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/gen/genesis"
|
||||
"github.com/filecoin-project/lotus/chain/state"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/chain/vm"
|
||||
"github.com/filecoin-project/lotus/chain/wallet"
|
||||
)
|
||||
|
||||
var _ vstate.VMWrapper = &StateWrapper{}
|
||||
|
||||
type StateWrapper struct {
|
||||
// The blockstore underlying the state tree and storage.
|
||||
bs blockstore.Blockstore
|
||||
|
||||
ds datastore.Batching
|
||||
// HAMT-CBOR store on top of the blockstore.
|
||||
cst cbor.IpldStore
|
||||
// A store for encryption keys.
|
||||
keys *keyStore
|
||||
|
||||
// CID of the root of the state tree.
|
||||
stateRoot cid.Cid
|
||||
// The root node of the state tree, essentially a cache of LoadStateTree(cst, stateRoot)
|
||||
//tree *state.StateTree
|
||||
// A look-through storage implementation.
|
||||
storage *directStorage
|
||||
}
|
||||
|
||||
var _ vstate.Wrapper = &StateWrapper{}
|
||||
func NewState() *StateWrapper {
|
||||
bs := blockstore.NewBlockstore(datastore.NewMapDatastore())
|
||||
cst := cbor.NewCborStore(bs)
|
||||
// Put EmptyObjectCid value in the store. When an actor is initially created its Head is set to this value.
|
||||
_, err := cst.Put(context.TODO(), map[string]string{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
treeImpl, err := state.NewStateTree(cst)
|
||||
if err != nil {
|
||||
panic(err) // Never returns error, the error return should be removed.
|
||||
}
|
||||
root, err := treeImpl.Flush(context.TODO())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &StateWrapper{
|
||||
bs: bs,
|
||||
ds: datastore.NewMapDatastore(),
|
||||
cst: cst,
|
||||
stateRoot: root,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StateWrapper) Root() cid.Cid {
|
||||
return s.stateRoot
|
||||
}
|
||||
|
||||
func (s *StateWrapper) Store() adt.Store {
|
||||
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &contextStore{tree.Store, context.Background()}
|
||||
}
|
||||
|
||||
func (s *StateWrapper) Actor(addr address.Address) (vstate.Actor, error) {
|
||||
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fcActor, err := tree.GetActor(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &actorWrapper{*fcActor}, nil
|
||||
}
|
||||
|
||||
func (s *StateWrapper) SetActorState(addr address.Address, balance abi.TokenAmount, actorState runtime.CBORMarshaler) (vstate.Actor, error) {
|
||||
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// actor should exist
|
||||
act, err := tree.GetActor(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// add the state to the store and get a new head cid
|
||||
actHead, err := tree.Store.Put(context.Background(), actorState)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// update the actor object with new head and balance parameter
|
||||
actr := &actorWrapper{types.Actor{
|
||||
Code: act.Code,
|
||||
Nonce: act.Nonce,
|
||||
// updates
|
||||
Head: actHead,
|
||||
Balance: balance,
|
||||
}}
|
||||
if err := tree.SetActor(addr, &actr.Actor); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return actr, s.flush(tree)
|
||||
}
|
||||
|
||||
func (s *StateWrapper) CreateActor(code cid.Cid, addr address.Address, balance abi.TokenAmount, actorState runtime.CBORMarshaler) (vstate.Actor, address.Address, error) {
|
||||
if addr == builtin.InitActorAddr || addr == builtin.StoragePowerActorAddr || addr == builtin.StorageMarketActorAddr {
|
||||
act, err := s.SetupSingletonActor(addr)
|
||||
if err != nil {
|
||||
return nil, address.Undef, err
|
||||
}
|
||||
return act, addr, nil
|
||||
}
|
||||
tree, err := state.LoadStateTree(s.cst, s.Root())
|
||||
if err != nil {
|
||||
return nil, address.Undef, err
|
||||
}
|
||||
actHead, err := tree.Store.Put(context.Background(), actorState)
|
||||
if err != nil {
|
||||
return nil, address.Undef, err
|
||||
}
|
||||
actr := &actorWrapper{types.Actor{
|
||||
Code: code,
|
||||
Head: actHead,
|
||||
Balance: balance,
|
||||
}}
|
||||
|
||||
idAddr, err := tree.RegisterNewAddress(addr, &actr.Actor)
|
||||
if err != nil {
|
||||
return nil, address.Undef, xerrors.Errorf("register new address for actor: %w", err)
|
||||
}
|
||||
|
||||
if err := tree.SetActor(addr, &actr.Actor); err != nil {
|
||||
return nil, address.Undef, xerrors.Errorf("setting new actor for actor: %w", err)
|
||||
}
|
||||
|
||||
return actr, idAddr, s.flush(tree)
|
||||
}
|
||||
|
||||
// Flushes a state tree to storage and sets this state's root to that tree's root CID.
|
||||
func (s *StateWrapper) flush(tree *state.StateTree) (err error) {
|
||||
s.stateRoot, err = tree.Flush(context.TODO())
|
||||
return
|
||||
}
|
||||
|
||||
//
|
||||
// Actor Wrapper
|
||||
//
|
||||
|
||||
type actorWrapper struct {
|
||||
types.Actor
|
||||
}
|
||||
|
||||
func (a *actorWrapper) Code() cid.Cid {
|
||||
return a.Actor.Code
|
||||
}
|
||||
|
||||
func (a *actorWrapper) Head() cid.Cid {
|
||||
return a.Actor.Head
|
||||
}
|
||||
|
||||
func (a *actorWrapper) CallSeqNum() int64 {
|
||||
return int64(a.Actor.Nonce)
|
||||
}
|
||||
|
||||
func (a *actorWrapper) Balance() big.Int {
|
||||
return a.Actor.Balance
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Storage
|
||||
//
|
||||
|
||||
type contextStore struct {
|
||||
cbor.IpldStore
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func (s *contextStore) Context() context.Context {
|
||||
return s.ctx
|
||||
}
|
||||
|
||||
func (s *StateWrapper) SetupSingletonActor(addr address.Address) (vstate.Actor, error) {
|
||||
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch addr {
|
||||
case builtin.InitActorAddr:
|
||||
// FIXME this is going to be a problem if go-filecoin and lotus setup their init actors with different netnames
|
||||
// ideally lotus should use the init actor constructor
|
||||
initact, err := genesis.SetupInitActor(s.bs, "chain-validation", nil)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("setup init actor: %w", err)
|
||||
}
|
||||
if err := tree.SetActor(builtin.InitActorAddr, initact); err != nil {
|
||||
return nil, xerrors.Errorf("set init actor: %w", err)
|
||||
}
|
||||
|
||||
return &actorWrapper{*initact}, s.flush(tree)
|
||||
case builtin.StorageMarketActorAddr:
|
||||
smact, err := genesis.SetupStorageMarketActor(s.bs)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("setup storage marker actor: %w", err)
|
||||
}
|
||||
|
||||
if err := tree.SetActor(builtin.StorageMarketActorAddr, smact); err != nil {
|
||||
return nil, xerrors.Errorf("set storage marker actor: %w", err)
|
||||
}
|
||||
|
||||
return &actorWrapper{*smact}, s.flush(tree)
|
||||
case builtin.StoragePowerActorAddr:
|
||||
spact, err := genesis.SetupStoragePowerActor(s.bs)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("setup storage power actor: %w", err)
|
||||
}
|
||||
if err := tree.SetActor(builtin.StoragePowerActorAddr, spact); err != nil {
|
||||
return nil, xerrors.Errorf("set storage power actor: %w", err)
|
||||
}
|
||||
return &actorWrapper{*spact}, s.flush(tree)
|
||||
default:
|
||||
return nil, xerrors.Errorf("%v is not a singleton actor address", addr)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func NewState() *StateWrapper {
|
||||
bs := blockstore.NewBlockstore(datastore.NewMapDatastore())
|
||||
cst := cbor.NewCborStore(bs)
|
||||
@ -72,7 +262,7 @@ func (s *StateWrapper) Cid() cid.Cid {
|
||||
return s.stateRoot
|
||||
}
|
||||
|
||||
func (s *StateWrapper) Actor(addr vaddress.Address) (vstate.Actor, error) {
|
||||
func (s *StateWrapper) Actor(addr address.Address) (vstate.Actor, error) {
|
||||
vaddr, err := address.NewFromBytes(addr.Bytes())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -88,15 +278,15 @@ func (s *StateWrapper) Actor(addr vaddress.Address) (vstate.Actor, error) {
|
||||
return &actorWrapper{*fcActor}, nil
|
||||
}
|
||||
|
||||
func (s *StateWrapper) Storage(addr vaddress.Address) (vstate.Storage, error) {
|
||||
func (s *StateWrapper) Storage(addr address.Address) (vstate.Storage, error) {
|
||||
return s.storage, nil
|
||||
}
|
||||
|
||||
func (s *StateWrapper) NewAccountAddress() (vaddress.Address, error) {
|
||||
func (s *StateWrapper) NewAccountAddress() (address.Address, error) {
|
||||
return s.keys.NewAddress()
|
||||
}
|
||||
|
||||
func (s *StateWrapper) SetActor(addr vaddress.Address, code vactors.ActorCodeID, balance vtypes.BigInt) (vstate.Actor, vstate.Storage, error) {
|
||||
func (s *StateWrapper) SetActor(addr address.Address, code vactors.ActorCodeID, balance vtypes.BigInt) (vstate.Actor, vstate.Storage, error) {
|
||||
addrInt, err := address.NewFromBytes(addr.Bytes())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@ -192,7 +382,7 @@ func (s *StateWrapper) SetSingletonActor(addr vactors.SingletonActorID, balance
|
||||
}
|
||||
}
|
||||
|
||||
func (s *StateWrapper) Sign(ctx context.Context, addr vaddress.Address, data []byte) (*vtypes.Signature, error) {
|
||||
func (s *StateWrapper) Sign(ctx context.Context, addr address.Address, data []byte) (*vtypes.Signature, error) {
|
||||
sig, err := s.keys.Sign(ctx, addr, data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -218,23 +408,23 @@ func (s *StateWrapper) flush(tree *state.StateTree) (err error) {
|
||||
//
|
||||
type keyStore struct {
|
||||
// Private keys by address
|
||||
keys map[vaddress.Address]vtypes.KeyInfo
|
||||
keys map[address.Address]vtypes.KeyInfo
|
||||
// Seed for deterministic key generation.
|
||||
seed int64
|
||||
}
|
||||
|
||||
func newKeyStore() *keyStore {
|
||||
return &keyStore{
|
||||
keys: make(map[vaddress.Address]vtypes.KeyInfo),
|
||||
keys: make(map[address.Address]vtypes.KeyInfo),
|
||||
seed: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *keyStore) NewAddress() (vaddress.Address, error) {
|
||||
func (s *keyStore) NewAddress() (address.Address, error) {
|
||||
randSrc := rand.New(rand.NewSource(s.seed))
|
||||
prv, err := crypto.GenerateKeyFromSeed(randSrc)
|
||||
if err != nil {
|
||||
return vaddress.Undef, err
|
||||
return address.Undef, err
|
||||
}
|
||||
|
||||
vki := vtypes.KeyInfo{
|
||||
@ -246,18 +436,18 @@ func (s *keyStore) NewAddress() (vaddress.Address, error) {
|
||||
PrivateKey: vki.PrivateKey,
|
||||
})
|
||||
if err != nil {
|
||||
return vaddress.Undef, err
|
||||
return address.Undef, err
|
||||
}
|
||||
vaddr, err := vaddress.NewFromBytes(key.Address.Bytes())
|
||||
vaddr, err := address.NewFromBytes(key.Address.Bytes())
|
||||
if err != nil {
|
||||
return vaddress.Undef, err
|
||||
return address.Undef, err
|
||||
}
|
||||
s.keys[vaddr] = vki
|
||||
s.seed++
|
||||
return vaddress.NewFromBytes(key.Address.Bytes())
|
||||
return address.NewFromBytes(key.Address.Bytes())
|
||||
}
|
||||
|
||||
func (s *keyStore) Sign(ctx context.Context, addr vaddress.Address, data []byte) (*types.Signature, error) {
|
||||
func (s *keyStore) Sign(ctx context.Context, addr address.Address, data []byte) (*types.Signature, error) {
|
||||
ki, ok := s.keys[addr]
|
||||
if !ok {
|
||||
return &types.Signature{}, fmt.Errorf("unknown address %v", addr)
|
||||
@ -273,30 +463,6 @@ func (s *keyStore) Sign(ctx context.Context, addr vaddress.Address, data []byte)
|
||||
}, nil
|
||||
}
|
||||
|
||||
//
|
||||
// Actor Wrapper
|
||||
//
|
||||
|
||||
type actorWrapper struct {
|
||||
types.Actor
|
||||
}
|
||||
|
||||
func (a *actorWrapper) Code() cid.Cid {
|
||||
return a.Actor.Code
|
||||
}
|
||||
|
||||
func (a *actorWrapper) Head() cid.Cid {
|
||||
return a.Actor.Head
|
||||
}
|
||||
|
||||
func (a *actorWrapper) Nonce() uint64 {
|
||||
return a.Actor.Nonce
|
||||
}
|
||||
|
||||
func (a *actorWrapper) Balance() vtypes.BigInt {
|
||||
return vtypes.NewInt(a.Actor.Balance.Uint64())
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Storage
|
||||
@ -313,54 +479,4 @@ func (d *directStorage) Get(c cid.Cid, out interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func fromActorCode(code vactors.ActorCodeID) cid.Cid {
|
||||
switch code {
|
||||
case vactors.AccountActorCodeCid:
|
||||
return actors.AccountCodeCid
|
||||
case vactors.StorageMinerCodeCid:
|
||||
return actors.StorageMinerCodeCid
|
||||
case vactors.MultisigActorCodeCid:
|
||||
return actors.MultisigCodeCid
|
||||
case vactors.PaymentChannelActorCodeCid:
|
||||
return actors.PaymentChannelCodeCid
|
||||
default:
|
||||
panic(fmt.Errorf("unknown actor code: %v", code))
|
||||
}
|
||||
}
|
||||
|
||||
func fromSingletonAddress(addr vactors.SingletonActorID) vaddress.Address {
|
||||
switch addr {
|
||||
case vactors.InitAddress:
|
||||
out, err := vaddress.NewFromBytes(actors.InitAddress.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return out
|
||||
case vactors.NetworkAddress:
|
||||
out, err := vaddress.NewFromBytes(actors.NetworkAddress.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return out
|
||||
case vactors.StorageMarketAddress:
|
||||
out, err := vaddress.NewFromBytes(actors.StorageMarketAddress.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return out
|
||||
case vactors.BurntFundsAddress:
|
||||
out, err := vaddress.NewFromBytes(actors.BurntFundsAddress.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return out
|
||||
case vactors.StoragePowerAddress:
|
||||
out, err := vaddress.NewFromBytes(actors.StoragePowerAddress.Bytes())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return out
|
||||
default:
|
||||
panic(fmt.Errorf("unknown singleton actor address: %v", addr))
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
@ -11,7 +11,9 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime"
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||
)
|
||||
|
||||
type basicContract struct{}
|
||||
@ -58,19 +60,19 @@ func (b basicContract) Exports() []interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
func (basicContract) InvokeSomething0(act *types.Actor, vmctx types.VMContext,
|
||||
params *basicParams) ([]byte, aerrors.ActorError) {
|
||||
return nil, aerrors.New(params.B, "params.B")
|
||||
func (basicContract) InvokeSomething0(rt runtime.Runtime, params *basicParams) *adt.EmptyValue {
|
||||
rt.Abortf(exitcode.ExitCode(params.B), "params.B")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (basicContract) BadParam(act *types.Actor, vmctx types.VMContext,
|
||||
params *basicParams) ([]byte, aerrors.ActorError) {
|
||||
return nil, aerrors.New(255, "bad params")
|
||||
func (basicContract) BadParam(rt runtime.Runtime, params *basicParams) *adt.EmptyValue {
|
||||
rt.Abortf(255, "bad params")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (basicContract) InvokeSomething10(act *types.Actor, vmctx types.VMContext,
|
||||
params *basicParams) ([]byte, aerrors.ActorError) {
|
||||
return nil, aerrors.New(params.B+10, "params.B")
|
||||
func (basicContract) InvokeSomething10(rt runtime.Runtime, params *basicParams) *adt.EmptyValue {
|
||||
rt.Abortf(exitcode.ExitCode(params.B+10), "params.B")
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestInvokerBasic(t *testing.T) {
|
||||
|
@ -1,36 +1,65 @@
|
||||
package vm_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/filecoin-project/chain-validation/pkg/suites"
|
||||
suites "github.com/filecoin-project/chain-validation/suites"
|
||||
"github.com/filecoin-project/chain-validation/suites/message"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/validation"
|
||||
factory "github.com/filecoin-project/lotus/chain/validation"
|
||||
)
|
||||
|
||||
func TestStorageMinerValidation(t *testing.T) {
|
||||
t.SkipNow()
|
||||
factory := validation.NewFactories()
|
||||
suites.CreateStorageMinerAndUpdatePeerID(t, factory)
|
||||
|
||||
// TestSkipper contains a list of test cases skipped by the implementation.
|
||||
type TestSkipper struct {
|
||||
testSkips []suites.TestCase
|
||||
}
|
||||
|
||||
func TestValueTransfer(t *testing.T) {
|
||||
factory := validation.NewFactories()
|
||||
suites.AccountValueTransferSuccess(t, factory, 126)
|
||||
suites.AccountValueTransferZeroFunds(t, factory, 112)
|
||||
suites.AccountValueTransferOverBalanceNonZero(t, factory, 0)
|
||||
suites.AccountValueTransferOverBalanceZero(t, factory, 0)
|
||||
suites.AccountValueTransferToSelf(t, factory, 0)
|
||||
suites.AccountValueTransferFromKnownToUnknownAccount(t, factory, 0)
|
||||
suites.AccountValueTransferFromUnknownToKnownAccount(t, factory, 0)
|
||||
suites.AccountValueTransferFromUnknownToUnknownAccount(t, factory, 0)
|
||||
// Skip return true if the sutire.TestCase should be skipped.
|
||||
func (ts *TestSkipper) Skip(test suites.TestCase) bool {
|
||||
for _, skip := range ts.testSkips {
|
||||
if reflect.ValueOf(skip).Pointer() == reflect.ValueOf(test).Pointer() {
|
||||
fmt.Printf("=== SKIP %v\n", runtime.FuncForPC(reflect.ValueOf(test).Pointer()).Name())
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestMultiSig(t *testing.T) {
|
||||
t.SkipNow()
|
||||
factory := validation.NewFactories()
|
||||
suites.MultiSigActorConstructor(t, factory)
|
||||
suites.MultiSigActorProposeApprove(t, factory)
|
||||
suites.MultiSigActorProposeCancel(t, factory)
|
||||
// TestSuiteSkips contains tests we wish to skip.
|
||||
var TestSuiteSkipper TestSkipper
|
||||
|
||||
func init() {
|
||||
// initialize the test skipper with tests being skipped
|
||||
TestSuiteSkipper = TestSkipper{testSkips: []suites.TestCase{
|
||||
|
||||
// Fails due to gas mismatches
|
||||
message.TestPaych,
|
||||
// Fails due to state initialization
|
||||
message.TestMultiSigActor,
|
||||
// Fails due to state initialization
|
||||
//message.TestMessageApplicationEdgecases,
|
||||
}}
|
||||
}
|
||||
|
||||
func TestChainValidationMessageSuite(t *testing.T) {
|
||||
f := factory.NewFactories()
|
||||
for _, testCase := range suites.MessageTestCases() {
|
||||
if TestSuiteSkipper.Skip(testCase) {
|
||||
continue
|
||||
}
|
||||
testCase(t, f)
|
||||
}
|
||||
}
|
||||
|
||||
func TestChainValidationTipSetSuite(t *testing.T) {
|
||||
f := factory.NewFactories()
|
||||
for _, testCase := range suites.TipSetTestCases() {
|
||||
if TestSuiteSkipper.Skip(testCase) {
|
||||
continue
|
||||
}
|
||||
testCase(t, f)
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime"
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
||||
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||
@ -358,6 +359,7 @@ type Rand interface {
|
||||
type ApplyRet struct {
|
||||
types.MessageReceipt
|
||||
ActorErr aerrors.ActorError
|
||||
Penalty big.Int
|
||||
}
|
||||
|
||||
func (vm *VM) send(ctx context.Context, msg *types.Message, parent *VMContext,
|
||||
@ -454,7 +456,15 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
||||
|
||||
fromActor, err := st.GetActor(msg.From)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("from actor not found: %w", err)
|
||||
if xerrors.Is(err, types.ErrActorNotFound) {
|
||||
return &ApplyRet{
|
||||
MessageReceipt: types.MessageReceipt{
|
||||
ExitCode: exitcode.SysErrActorNotFound,
|
||||
GasUsed: msg.GasLimit,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
return nil, xerrors.Errorf("failed to look up from actor: %w", err)
|
||||
}
|
||||
|
||||
serMsg, err := msg.Serialize()
|
||||
@ -466,7 +476,12 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
||||
gascost := types.BigMul(msg.GasLimit, msg.GasPrice)
|
||||
totalCost := types.BigAdd(gascost, msg.Value)
|
||||
if fromActor.Balance.LessThan(totalCost) {
|
||||
return nil, xerrors.Errorf("not enough funds (%s < %s)", fromActor.Balance, totalCost)
|
||||
return &ApplyRet{
|
||||
MessageReceipt: types.MessageReceipt{
|
||||
ExitCode: exitcode.SysErrInsufficientFunds,
|
||||
GasUsed: msg.GasLimit,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
gasHolder := &types.Actor{Balance: types.NewInt(0)}
|
||||
@ -475,7 +490,12 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
||||
}
|
||||
|
||||
if msg.Nonce != fromActor.Nonce {
|
||||
return nil, xerrors.Errorf("invalid nonce (got %d, expected %d)", msg.Nonce, fromActor.Nonce)
|
||||
return &ApplyRet{
|
||||
MessageReceipt: types.MessageReceipt{
|
||||
ExitCode: exitcode.SysErrInvalidCallSeqNum,
|
||||
GasUsed: msg.GasLimit,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
fromActor.Nonce++
|
||||
|
||||
@ -506,15 +526,15 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
||||
}
|
||||
}
|
||||
|
||||
miner, err := st.GetActor(vm.blockMiner)
|
||||
bfact, err := st.GetActor(builtin.BurntFundsActorAddr)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("getting block miner actor (%s) failed: %w", vm.blockMiner, err)
|
||||
return nil, xerrors.Errorf("getting burnt funds actor failed: %w", err)
|
||||
}
|
||||
|
||||
// TODO: support multiple blocks in a tipset
|
||||
// TODO: actually wire this up (miner is undef for now)
|
||||
gasReward := types.BigMul(msg.GasPrice, gasUsed)
|
||||
if err := Transfer(gasHolder, miner, gasReward); err != nil {
|
||||
if err := Transfer(gasHolder, bfact, gasReward); err != nil {
|
||||
return nil, xerrors.Errorf("failed to give miner gas reward: %w", err)
|
||||
}
|
||||
|
||||
@ -524,7 +544,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
||||
|
||||
return &ApplyRet{
|
||||
MessageReceipt: types.MessageReceipt{
|
||||
ExitCode: errcode,
|
||||
ExitCode: exitcode.ExitCode(errcode),
|
||||
Return: ret,
|
||||
GasUsed: gasUsed,
|
||||
},
|
||||
|
@ -14,6 +14,7 @@ import (
|
||||
const HalvingPeriodEpochs = 6 * 365 * 24 * 60 * 2
|
||||
|
||||
func TestBlockReward(t *testing.T) {
|
||||
t.Skip()
|
||||
coffer := types.FromFil(build.MiningRewardTotal).Int
|
||||
sum := new(big.Int)
|
||||
N := HalvingPeriodEpochs
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
lcli "github.com/filecoin-project/lotus/cli"
|
||||
"github.com/filecoin-project/lotus/miner"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
@ -68,7 +69,7 @@ func init() {
|
||||
}
|
||||
|
||||
epostp := &types.EPostProof{
|
||||
Proof: []byte("valid proof"),
|
||||
Proofs: []abi.PoStProof{{ProofBytes: []byte("valid proof")}},
|
||||
Candidates: []types.EPostTicket{
|
||||
{
|
||||
ChallengeIndex: 0,
|
||||
|
6
go.mod
6
go.mod
@ -10,7 +10,7 @@ require (
|
||||
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
|
||||
github.com/coreos/go-systemd/v22 v22.0.0
|
||||
github.com/docker/go-units v0.4.0
|
||||
github.com/filecoin-project/chain-validation v0.0.3
|
||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200303230205-30309cc5d8eb
|
||||
github.com/filecoin-project/filecoin-ffi v0.0.0-20200226231125-fc253ccb5294
|
||||
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be
|
||||
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e
|
||||
@ -18,7 +18,7 @@ require (
|
||||
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
|
||||
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce
|
||||
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5
|
||||
github.com/filecoin-project/go-fil-markets v0.0.0-20200228192824-ee51014cc8c6
|
||||
github.com/filecoin-project/go-fil-markets v0.0.0-20200303015849-1159079679ca
|
||||
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6
|
||||
github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663
|
||||
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200229022239-442fe78a3168
|
||||
@ -44,7 +44,7 @@ require (
|
||||
github.com/ipfs/go-fs-lock v0.0.1
|
||||
github.com/ipfs/go-graphsync v0.0.4
|
||||
github.com/ipfs/go-hamt-ipld v0.0.15-0.20200204200533-99b8553ef242
|
||||
github.com/ipfs/go-ipfs-blockstore v0.1.1
|
||||
github.com/ipfs/go-ipfs-blockstore v0.1.3
|
||||
github.com/ipfs/go-ipfs-chunker v0.0.1
|
||||
github.com/ipfs/go-ipfs-ds-help v0.0.1
|
||||
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
|
||||
|
18
go.sum
18
go.sum
@ -72,6 +72,7 @@ github.com/cskr/pubsub v1.0.2 h1:vlOzMhl6PFn60gRlTQQsIfVwaPB/B/8MziK8FhEPt/0=
|
||||
github.com/cskr/pubsub v1.0.2/go.mod h1:/8MzYXk/NJAz782G8RPkFzXTZVu63VotefPnR9TIRis=
|
||||
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
|
||||
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
|
||||
github.com/dave/jennifer v1.4.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
@ -97,8 +98,9 @@ github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFP
|
||||
github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY=
|
||||
github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8=
|
||||
github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
|
||||
github.com/filecoin-project/chain-validation v0.0.3 h1:luT/8kJ0WdMIqQ9Bm31W4JkuYCW0wUb26AvnD4WK59M=
|
||||
github.com/filecoin-project/chain-validation v0.0.3/go.mod h1:NCEGFjcWRjb8akWFSOXvU6n2efkWIqAeOKU6o5WBGQw=
|
||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200303230205-30309cc5d8eb h1:vGm95uLk+4ytckKQX8mfOwMzgBge9rqHbTfDsImUWIs=
|
||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200303230205-30309cc5d8eb/go.mod h1:6FYR4Xi26mfXkNlrHOo7fZjITZ9GrqqF8OKG4IQ4zWk=
|
||||
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5 h1:/MmWluswvDIbuPvBct4q6HeQgVm62O2DzWYTB38kt4A=
|
||||
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
|
||||
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be h1:TooKBwR/g8jG0hZ3lqe9S5sy2vTUcLOZLlz3M5wGn2E=
|
||||
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
|
||||
@ -112,8 +114,8 @@ github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce
|
||||
github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce/go.mod h1:b14UWxhxVCAjrQUYvVGrQRRsjAh79wXYejw9RbUcAww=
|
||||
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5 h1:yvQJCW9mmi9zy+51xA01Ea2X7/dL7r8eKDPuGUjRmbo=
|
||||
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5/go.mod h1:JbkIgFF/Z9BDlvrJO1FuKkaWsH673/UdFaiVS6uIHlA=
|
||||
github.com/filecoin-project/go-fil-markets v0.0.0-20200228192824-ee51014cc8c6 h1:xYldVV9fZ+nsykQnEVMwcLU+6R5EshzmOWcyQDpludc=
|
||||
github.com/filecoin-project/go-fil-markets v0.0.0-20200228192824-ee51014cc8c6/go.mod h1:rfRwhd3ujcCXnD4N9oEM2wjh8GRZGoeNXME+UPG/9ts=
|
||||
github.com/filecoin-project/go-fil-markets v0.0.0-20200303015849-1159079679ca h1:EccB/LgjrA6EVSpaVDfQyWe1DS3c0x1DcASBQ8beUdg=
|
||||
github.com/filecoin-project/go-fil-markets v0.0.0-20200303015849-1159079679ca/go.mod h1:rfRwhd3ujcCXnD4N9oEM2wjh8GRZGoeNXME+UPG/9ts=
|
||||
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6 h1:92PET+sx1Hb4W/8CgFwGuxaKbttwY+UNspYZTvXY0vs=
|
||||
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6/go.mod h1:0HgYnrkeSU4lu1p+LEOeDpFsNBssa0OGGriWdA4hvaE=
|
||||
github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663 h1:eYxi6vI5CyeXD15X1bB3bledDXbqKxqf0wQzTLgwYwA=
|
||||
@ -128,6 +130,9 @@ github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIi
|
||||
github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200210130641-2d1fbd8672cf/go.mod h1:xtDZUB6pe4Pksa/bAJbJ693OilaC5Wbot9jMhLm3cZA=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226200336-94c9b92b2775/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200226200336-94c9b92b2775/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200302223606-0eaf97b10aaf h1:3IojVqJAD5IXMxvZ+WYx+LRbfSB/rOXpYBuHh6o3XkY=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200302223606-0eaf97b10aaf/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04 h1:O343OeQLkLWLj5ZqQ5nhevAGBTeB5LioiA53ddScqdY=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200302223606-0eaf97b10aaf h1:3IojVqJAD5IXMxvZ+WYx+LRbfSB/rOXpYBuHh6o3XkY=
|
||||
@ -269,8 +274,8 @@ github.com/ipfs/go-hamt-ipld v0.0.15-0.20200204200533-99b8553ef242 h1:OYVGeYkGSR
|
||||
github.com/ipfs/go-hamt-ipld v0.0.15-0.20200204200533-99b8553ef242/go.mod h1:kq3Pi+UP3oHhAdKexE+kHHYRKMoFNuGero0R7q3hWGg=
|
||||
github.com/ipfs/go-ipfs-blockstore v0.0.1/go.mod h1:d3WClOmRQKFnJ0Jz/jj/zmksX0ma1gROTlovZKBmN08=
|
||||
github.com/ipfs/go-ipfs-blockstore v0.1.0/go.mod h1:5aD0AvHPi7mZc6Ci1WCAhiBQu2IsfTduLl+422H6Rqw=
|
||||
github.com/ipfs/go-ipfs-blockstore v0.1.1 h1:+PAFREAlSxLs9IEtrRcnJ/DqWkGlDa+l547WFZnohNw=
|
||||
github.com/ipfs/go-ipfs-blockstore v0.1.1/go.mod h1:8gZOgIN5e+Xdg2YSGdwTTRbguSVjYyosIDRQCY8E9QM=
|
||||
github.com/ipfs/go-ipfs-blockstore v0.1.3 h1:Nc/Uwc8KZgo5PsMUZT/Zt7zc0u/s+b/3c64ChQNttHc=
|
||||
github.com/ipfs/go-ipfs-blockstore v0.1.3/go.mod h1:iNWVBoSQ7eMcaGo8+L3pKZABGTdWcqj1/hpoUu5bDps=
|
||||
github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ=
|
||||
github.com/ipfs/go-ipfs-blocksutil v0.0.1/go.mod h1:Yq4M86uIOmxmGPUHv/uI7uKqZNtLb449gwKqXjIsnRk=
|
||||
github.com/ipfs/go-ipfs-chunker v0.0.1 h1:cHUUxKFQ99pozdahi+uSC/3Y6HeRpi9oTeUHbE27SEw=
|
||||
@ -770,7 +775,6 @@ github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc h1:BCPnHtcboa
|
||||
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc/go.mod h1:r45hJU7yEoA81k6MWNhpMj/kms0n14dkzkxYHoB96UM=
|
||||
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba h1:X4n8JG2e2biEZZXdBKt9HX7DN3bYGFUqljqqy0DqgnY=
|
||||
github.com/whyrusleeping/bencher v0.0.0-20190829221104-bb6607aa8bba/go.mod h1:CHQnYnQUEPydYCwuy8lmTHfGmdw9TKrhWV0xLx8l0oM=
|
||||
github.com/whyrusleeping/cbor-gen v0.0.0-20191116002219-891f55cd449d/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||
github.com/whyrusleeping/cbor-gen v0.0.0-20191212224538-d370462a7e8a/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||
github.com/whyrusleeping/cbor-gen v0.0.0-20191216205031-b047b6acb3c0/go.mod h1:xdlJQaiqipF0HW+Mzpg7XRM3fWbGvfgFlcppuvlkIvY=
|
||||
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 h1:WXhVOwj2USAXB5oMDwRl3piOux2XMV9TANaYxXHdkoE=
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/storage"
|
||||
"github.com/filecoin-project/lotus/storage/sealmgr"
|
||||
)
|
||||
@ -27,6 +28,11 @@ func NewRetrievalProviderNode(miner *storage.Miner, sealer sealmgr.Manager, full
|
||||
return &retrievalProviderNode{miner, sealer, full}
|
||||
}
|
||||
|
||||
func (rpn *retrievalProviderNode) GetMinerWorker(ctx context.Context, miner address.Address) (address.Address, error) {
|
||||
addr, err := rpn.full.StateMinerWorker(ctx, miner, types.EmptyTSK)
|
||||
return addr, err
|
||||
}
|
||||
|
||||
func (rpn *retrievalProviderNode) UnsealSector(ctx context.Context, sectorID uint64, offset uint64, length uint64) (io.ReadCloser, error) {
|
||||
si, err := rpn.miner.GetSectorInfo(abi.SectorNumber(sectorID))
|
||||
if err != nil {
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/stmgr"
|
||||
"github.com/filecoin-project/lotus/chain/store"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/lib/sigs"
|
||||
"github.com/filecoin-project/lotus/markets/utils"
|
||||
"github.com/filecoin-project/lotus/node/impl/full"
|
||||
)
|
||||
@ -92,8 +93,8 @@ func (n *ClientNodeAdapter) ListStorageProviders(ctx context.Context) ([]*storag
|
||||
}
|
||||
|
||||
func (n *ClientNodeAdapter) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) bool {
|
||||
log.Warn("stub VerifySignature")
|
||||
return true
|
||||
err := sigs.Verify(&sig, addr, input)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (n *ClientNodeAdapter) ListClientDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) {
|
||||
@ -328,13 +329,19 @@ func (c *ClientNodeAdapter) OnDealSectorCommitted(ctx context.Context, provider
|
||||
|
||||
func (n *ClientNodeAdapter) SignProposal(ctx context.Context, signer address.Address, proposal samarket.DealProposal) (*samarket.ClientDealProposal, error) {
|
||||
// TODO: output spec signed proposal
|
||||
log.Warn("TODO: stub SignProposal")
|
||||
buf, err := cborutil.Dump(&proposal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sig, err := n.Wallet.Sign(ctx, signer, buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &samarket.ClientDealProposal{
|
||||
Proposal: proposal,
|
||||
ClientSignature: crypto.Signature{
|
||||
Type: crypto.SigTypeBLS,
|
||||
Data: []byte{},
|
||||
},
|
||||
ClientSignature: *sig,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -356,9 +363,8 @@ func (n *ClientNodeAdapter) ValidateAskSignature(ask *storagemarket.SignedStorag
|
||||
return xerrors.Errorf("failed to re-serialize ask")
|
||||
}
|
||||
|
||||
_ = w
|
||||
_ = sigb
|
||||
panic("verify signature")
|
||||
return sigs.Verify(ask.Signature, w, sigb)
|
||||
|
||||
}
|
||||
|
||||
var _ storagemarket.StorageClientNode = &ClientNodeAdapter{}
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
"github.com/ipfs/go-cid"
|
||||
logging "github.com/ipfs/go-log"
|
||||
logging "github.com/ipfs/go-log/v2"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
@ -23,6 +23,7 @@ import (
|
||||
"github.com/filecoin-project/lotus/chain/actors"
|
||||
"github.com/filecoin-project/lotus/chain/events"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/lib/sigs"
|
||||
"github.com/filecoin-project/lotus/markets/utils"
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/storage/sealing"
|
||||
@ -109,8 +110,8 @@ func (n *ProviderNodeAdapter) OnDealComplete(ctx context.Context, deal storagema
|
||||
}
|
||||
|
||||
func (n *ProviderNodeAdapter) VerifySignature(sig crypto.Signature, addr address.Address, input []byte) bool {
|
||||
log.Warn("stub VerifySignature")
|
||||
return true
|
||||
err := sigs.Verify(&sig, addr, input)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (n *ProviderNodeAdapter) ListProviderDeals(ctx context.Context, addr address.Address) ([]storagemarket.StorageDeal, error) {
|
||||
|
@ -187,7 +187,7 @@ func (a *API) ClientFindData(ctx context.Context, root cid.Cid) ([]api.QueryOffe
|
||||
MinPrice: queryResponse.PieceRetrievalPrice(),
|
||||
PaymentInterval: queryResponse.MaxPaymentInterval,
|
||||
PaymentIntervalIncrease: queryResponse.MaxPaymentIntervalIncrease,
|
||||
Miner: p.Address, // TODO: check
|
||||
Miner: queryResponse.PaymentAddress, // TODO: check
|
||||
MinerPeerID: p.ID,
|
||||
}
|
||||
}
|
||||
@ -308,10 +308,10 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, path
|
||||
|
||||
unsubscribe := a.Retrieval.SubscribeToEvents(func(event retrievalmarket.ClientEvent, state retrievalmarket.ClientDealState) {
|
||||
if state.PayloadCID.Equals(order.Root) {
|
||||
switch event {
|
||||
case retrievalmarket.ClientEventError:
|
||||
switch state.Status {
|
||||
case retrievalmarket.DealStatusFailed, retrievalmarket.DealStatusErrored:
|
||||
retrievalResult <- xerrors.Errorf("Retrieval Error: %s", state.Message)
|
||||
case retrievalmarket.ClientEventComplete:
|
||||
case retrievalmarket.DealStatusCompleted:
|
||||
retrievalResult <- nil
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func (a *StateAPI) StateMinerPower(ctx context.Context, maddr address.Address, t
|
||||
if err != nil {
|
||||
return api.MinerPower{}, err
|
||||
}
|
||||
if slashed != 0 {
|
||||
if slashed {
|
||||
mpow = types.NewInt(0)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
cid "github.com/ipfs/go-cid"
|
||||
@ -76,7 +77,7 @@ func (a *SyncAPI) SyncSubmitBlock(ctx context.Context, blk *types.BlockMsg) erro
|
||||
}
|
||||
|
||||
// TODO: anything else to do here?
|
||||
return a.PubSub.Publish("/fil/blocks", b)
|
||||
return a.PubSub.Publish(build.MessagesTopic, b)
|
||||
}
|
||||
|
||||
func (a *SyncAPI) SyncIncomingBlocks(ctx context.Context) (<-chan *types.BlockHeader, error) {
|
||||
|
@ -80,7 +80,7 @@ func DHTRouting(client bool) interface{} {
|
||||
dhtopts.Client(client),
|
||||
dhtopts.Datastore(dstore),
|
||||
dhtopts.Validator(validator),
|
||||
dhtopts.Protocols("/lotus/kad/1.0.0"),
|
||||
dhtopts.Protocols(build.DhtProtocolName),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
||||
"github.com/filecoin-project/go-fil-markets/retrievalmarket/discovery"
|
||||
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
"github.com/filecoin-project/lotus/chain"
|
||||
"github.com/filecoin-project/lotus/chain/blocksync"
|
||||
"github.com/filecoin-project/lotus/chain/messagepool"
|
||||
@ -23,9 +24,6 @@ import (
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
)
|
||||
|
||||
const BlocksTopic = "/fil/blocks"
|
||||
const MessagesTopic = "/fil/messages"
|
||||
|
||||
func RunHello(mctx helpers.MetricsCtx, lc fx.Lifecycle, h host.Host, svc *hello.Service) {
|
||||
h.SetStreamHandler(hello.ProtocolID, svc.HandleStream)
|
||||
|
||||
@ -53,7 +51,7 @@ func RunBlockSync(h host.Host, svc *blocksync.BlockSyncService) {
|
||||
func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.PubSub, s *chain.Syncer, h host.Host) {
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
|
||||
blocksub, err := ps.Subscribe(BlocksTopic)
|
||||
blocksub, err := ps.Subscribe(build.BlocksTopic)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -63,7 +61,7 @@ func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.P
|
||||
h.ConnManager().TagPeer(p, "badblock", -1000)
|
||||
})
|
||||
|
||||
if err := ps.RegisterTopicValidator(BlocksTopic, v.Validate); err != nil {
|
||||
if err := ps.RegisterTopicValidator(build.BlocksTopic, v.Validate); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@ -73,7 +71,7 @@ func HandleIncomingBlocks(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.P
|
||||
func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub.PubSub, mpool *messagepool.MessagePool) {
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
|
||||
msgsub, err := ps.Subscribe(MessagesTopic)
|
||||
msgsub, err := ps.Subscribe(build.MessagesTopic)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -89,7 +87,7 @@ func HandleIncomingMessages(mctx helpers.MetricsCtx, lc fx.Lifecycle, ps *pubsub
|
||||
return true
|
||||
}
|
||||
|
||||
if err := ps.RegisterTopicValidator(MessagesTopic, v); err != nil {
|
||||
if err := ps.RegisterTopicValidator(build.MessagesTopic, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
|
||||
cborutil "github.com/filecoin-project/go-cbor-util"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/account"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin/paych"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
@ -69,6 +70,18 @@ func (pm *Manager) TrackInboundChannel(ctx context.Context, ch address.Address)
|
||||
return err
|
||||
}
|
||||
|
||||
var account account.State
|
||||
_, err = pm.sm.LoadActorState(ctx, st.From, &account, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
from := account.Address
|
||||
_, err = pm.sm.LoadActorState(ctx, st.From, &account, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
to := account.Address
|
||||
|
||||
maxLane, err := maxLaneFromState(st)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -76,8 +89,8 @@ func (pm *Manager) TrackInboundChannel(ctx context.Context, ch address.Address)
|
||||
|
||||
return pm.store.TrackChannel(&ChannelInfo{
|
||||
Channel: ch,
|
||||
Control: st.To,
|
||||
Target: st.From,
|
||||
Control: to,
|
||||
Target: from,
|
||||
|
||||
Direction: DirInbound,
|
||||
NextLane: maxLane + 1,
|
||||
@ -95,10 +108,22 @@ func (pm *Manager) loadOutboundChannelInfo(ctx context.Context, ch address.Addre
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var account account.State
|
||||
_, err = pm.sm.LoadActorState(ctx, st.From, &account, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
from := account.Address
|
||||
_, err = pm.sm.LoadActorState(ctx, st.From, &account, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
to := account.Address
|
||||
|
||||
return &ChannelInfo{
|
||||
Channel: ch,
|
||||
Control: st.From,
|
||||
Target: st.To,
|
||||
Control: from,
|
||||
Target: to,
|
||||
|
||||
Direction: DirOutbound,
|
||||
NextLane: maxLane + 1,
|
||||
@ -129,6 +154,13 @@ func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv
|
||||
return err
|
||||
}
|
||||
|
||||
var account account.State
|
||||
_, err = pm.sm.LoadActorState(ctx, pca.From, &account, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
from := account.Address
|
||||
|
||||
// verify signature
|
||||
vb, err := sv.SigningBytes()
|
||||
if err != nil {
|
||||
@ -138,7 +170,7 @@ func (pm *Manager) CheckVoucherValid(ctx context.Context, ch address.Address, sv
|
||||
// TODO: technically, either party may create and sign a voucher.
|
||||
// However, for now, we only accept them from the channel creator.
|
||||
// More complex handling logic can be added later
|
||||
if err := sigs.Verify(sv.Signature, pca.From, vb); err != nil {
|
||||
if err := sigs.Verify(sv.Signature, from, vb); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -258,7 +290,7 @@ func (pm *Manager) AddVoucher(ctx context.Context, ch address.Address, sv *paych
|
||||
|
||||
// look for duplicates
|
||||
for i, v := range ci.Vouchers {
|
||||
eq, err := cborutil.Equals(sv, v)
|
||||
eq, err := cborutil.Equals(sv, v.Voucher)
|
||||
if err != nil {
|
||||
return types.BigInt{}, err
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package paychmgr
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
@ -17,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func (pm *Manager) createPaych(ctx context.Context, from, to address.Address, amt types.BigInt) (address.Address, cid.Cid, error) {
|
||||
params, aerr := actors.SerializeParams(&paych.ConstructorParams{To: to})
|
||||
params, aerr := actors.SerializeParams(&paych.ConstructorParams{From: from, To: to})
|
||||
if aerr != nil {
|
||||
return address.Undef, cid.Undef, aerr
|
||||
}
|
||||
@ -58,10 +59,12 @@ func (pm *Manager) createPaych(ctx context.Context, from, to address.Address, am
|
||||
return address.Undef, cid.Undef, fmt.Errorf("payment channel creation failed (exit code %d)", mwait.Receipt.ExitCode)
|
||||
}
|
||||
|
||||
paychaddr, err := address.NewFromBytes(mwait.Receipt.Return)
|
||||
var decodedReturn init_.ExecReturn
|
||||
err = decodedReturn.UnmarshalCBOR(bytes.NewReader(mwait.Receipt.Return))
|
||||
if err != nil {
|
||||
return address.Undef, cid.Undef, err
|
||||
}
|
||||
paychaddr := decodedReturn.RobustAddress
|
||||
|
||||
ci, err := pm.loadOutboundChannelInfo(ctx, paychaddr)
|
||||
if err != nil {
|
||||
|
@ -14,16 +14,22 @@ import (
|
||||
"github.com/filecoin-project/go-sectorbuilder"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/ipfs/go-cid"
|
||||
logging "github.com/ipfs/go-log"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
|
||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||
)
|
||||
|
||||
var log = logging.Logger("sbmock")
|
||||
|
||||
type SBMock struct {
|
||||
sectors map[abi.SectorNumber]*sectorState
|
||||
sectorSize abi.SectorSize
|
||||
nextSectorID abi.SectorNumber
|
||||
rateLimit chan struct{}
|
||||
proofType abi.RegisteredProof
|
||||
|
||||
lk sync.Mutex
|
||||
}
|
||||
@ -31,11 +37,17 @@ type SBMock struct {
|
||||
type mockVerif struct{}
|
||||
|
||||
func NewMockSectorBuilder(threads int, ssize abi.SectorSize) *SBMock {
|
||||
rt, _, err := api.ProofTypeFromSectorSize(ssize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &SBMock{
|
||||
sectors: make(map[abi.SectorNumber]*sectorState),
|
||||
sectorSize: ssize,
|
||||
nextSectorID: 5,
|
||||
rateLimit: make(chan struct{}, threads),
|
||||
proofType: rt,
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,6 +76,7 @@ func (sb *SBMock) RateLimit() func() {
|
||||
}
|
||||
|
||||
func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sectorId abi.SectorNumber, r io.Reader, existingPieces []abi.UnpaddedPieceSize) (abi.PieceInfo, error) {
|
||||
log.Warn("Add piece: ", sectorId, size, sb.proofType)
|
||||
sb.lk.Lock()
|
||||
ss, ok := sb.sectors[sectorId]
|
||||
if !ok {
|
||||
@ -76,12 +89,12 @@ func (sb *SBMock) AddPiece(ctx context.Context, size abi.UnpaddedPieceSize, sect
|
||||
ss.lk.Lock()
|
||||
defer ss.lk.Unlock()
|
||||
|
||||
b, err := ioutil.ReadAll(r)
|
||||
c, err := sectorbuilder.GeneratePieceCIDFromFile(sb.proofType, r, size)
|
||||
if err != nil {
|
||||
return abi.PieceInfo{}, err
|
||||
return abi.PieceInfo{}, xerrors.Errorf("failed to generate piece cid: %w", err)
|
||||
}
|
||||
|
||||
c := commcid.DataCommitmentV1ToCID(b[:32]) // hax
|
||||
log.Warn("Generated Piece CID: ", c)
|
||||
|
||||
ss.pieces = append(ss.pieces, c)
|
||||
return abi.PieceInfo{
|
||||
@ -155,13 +168,14 @@ func (sb *SBMock) SealPreCommit1(ctx context.Context, sid abi.SectorNumber, tick
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cc[0] ^= 'd'
|
||||
|
||||
return cc, nil
|
||||
}
|
||||
|
||||
func (sb *SBMock) SealPreCommit2(ctx context.Context, sid abi.SectorNumber, phase1Out []byte) (sealedCID cid.Cid, unsealedCID cid.Cid, err error) {
|
||||
db := []byte(string(phase1Out[0]))
|
||||
db := []byte(string(phase1Out))
|
||||
db[0] ^= 'd'
|
||||
|
||||
d := commcid.DataCommitmentV1ToCID(db)
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func TestOpFinish(t *testing.T) {
|
||||
sb := NewMockSectorBuilder(1, 1024)
|
||||
sb := NewMockSectorBuilder(1, 2048)
|
||||
|
||||
sid, pieces, err := sb.StageFakeData()
|
||||
if err != nil {
|
||||
|
@ -108,7 +108,7 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se
|
||||
}
|
||||
|
||||
if cid.Cid(c) != *si.CommD {
|
||||
return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)}
|
||||
return &ErrBadCommD{xerrors.Errorf("on chain CommD differs from sector: %s != %s", cid.Cid(c), si.CommD)}
|
||||
}
|
||||
|
||||
if int64(head.Height())-int64(si.Ticket.Epoch+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit {
|
||||
|
@ -95,7 +95,7 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf
|
||||
case *ErrBadCommD: // TODO: Should this just back to packing? (not really needed since handleUnsealed will do that too)
|
||||
return ctx.Send(SectorSealFailed{xerrors.Errorf("bad CommD error: %w", err)})
|
||||
case *ErrExpiredTicket:
|
||||
return ctx.Send(SectorSealFailed{xerrors.Errorf("bad CommD error: %w", err)})
|
||||
return ctx.Send(SectorSealFailed{xerrors.Errorf("ticket expired: %w", err)})
|
||||
default:
|
||||
return xerrors.Errorf("checkSeal sanity check error: %w", err)
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ func RecordTipsetMessagesPoints(ctx context.Context, api api.FullNode, pl *Point
|
||||
tag := msgTag{
|
||||
actor: string(dm.Digest),
|
||||
method: uint64(msg.Message.Method),
|
||||
exitcode: recp[i].ExitCode,
|
||||
exitcode: uint8(recp[i].ExitCode),
|
||||
}
|
||||
|
||||
found := false
|
||||
|
Loading…
Reference in New Issue
Block a user