Update validation driver to match latest in chain-validation (#1532)

* update driver to match new chain-validation interfaces

* update chain-validation

* update filecoin-ffi

* gofmt

* update chain-validation again
This commit is contained in:
Frrist 2020-04-24 15:08:16 -07:00 committed by GitHub
parent e8e2b3a6f9
commit 0f0589bcf5
8 changed files with 74 additions and 53 deletions

View File

@ -157,7 +157,6 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, pstate cid.Cid, bms []B
var receipts []cbg.CBORMarshaler
processedMsgs := map[cid.Cid]bool{}
for _, b := range bms {
penalty := types.NewInt(0)
gasReward := big.Zero()

View File

@ -1,6 +1,5 @@
package validation
/*
import (
"context"
@ -24,22 +23,49 @@ import (
// Applier applies messages to state trees and storage.
type Applier struct {
stateWrapper *StateWrapper
}
var _ vstate.Applier = &Applier{}
func NewApplier() *Applier {
return &Applier{}
func NewApplier(sw *StateWrapper) *Applier {
return &Applier{sw}
}
func (a *Applier) ApplyMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWrapper, message *vtypes.Message) (vtypes.MessageReceipt, abi.TokenAmount, abi.TokenAmount, error) {
func (a *Applier) ApplyMessage(epoch abi.ChainEpoch, message *vtypes.Message) (vtypes.ApplyMessageResult, error) {
lm := toLotusMsg(message)
return a.applyMessage(eCtx, state, lm)
receipt, penalty, reward, err := a.applyMessage(epoch, lm)
return vtypes.ApplyMessageResult{
Receipt: receipt,
Penalty: penalty,
Reward: reward,
Root: a.stateWrapper.Root().String(),
}, err
}
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, vdrivers.NewChainValidationSyscalls())
func (a *Applier) ApplySignedMessage(epoch abi.ChainEpoch, msg *vtypes.SignedMessage) (vtypes.ApplyMessageResult, error) {
var lm types.ChainMsg
switch msg.Signature.Type {
case crypto.SigTypeSecp256k1:
lm = toLotusSignedMsg(msg)
case crypto.SigTypeBLS:
lm = toLotusMsg(&msg.Message)
default:
return vtypes.ApplyMessageResult{}, xerrors.New("Unknown signature type")
}
// TODO: Validate the sig first
receipt, penalty, reward, err := a.applyMessage(epoch, lm)
return vtypes.ApplyMessageResult{
Receipt: receipt,
Penalty: penalty,
Reward: reward,
Root: a.stateWrapper.Root().String(),
}, err
}
func (a *Applier) ApplyTipSetMessages(epoch abi.ChainEpoch, blocks []vtypes.BlockMessagesInfo, rnd vstate.RandomnessSource) (vtypes.ApplyTipSetResult, error) {
cs := store.NewChainStore(a.stateWrapper.bs, a.stateWrapper.ds, vdrivers.NewChainValidationSyscalls())
sm := stmgr.NewStateManager(cs)
var bms []stmgr.BlockMessages
@ -61,7 +87,7 @@ func (a *Applier) ApplyTipSetMessages(state vstate.VMWrapper, blocks []vtypes.Bl
}
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 {
sroot, _, err := sm.ApplyBlocks(context.TODO(), a.stateWrapper.Root(), bms, epoch, &randWrapper{rnd}, func(c cid.Cid, msg *types.Message, ret *vm.ApplyRet) error {
if msg.From == builtin.SystemActorAddr {
return nil // ignore reward and cron calls
}
@ -78,25 +104,15 @@ func (a *Applier) ApplyTipSetMessages(state vstate.VMWrapper, blocks []vtypes.Bl
return nil
})
if err != nil {
return nil, err
return vtypes.ApplyTipSetResult{}, err
}
state.(*StateWrapper).stateRoot = sroot
a.stateWrapper.stateRoot = sroot
return receipts, nil
}
func (a *Applier) ApplySignedMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWrapper, msg *vtypes.SignedMessage) (vtypes.MessageReceipt, abi.TokenAmount, abi.TokenAmount, error) {
var lm types.ChainMsg
switch msg.Signature.Type {
case crypto.SigTypeSecp256k1:
lm = toLotusSignedMsg(msg)
case crypto.SigTypeBLS:
lm = toLotusMsg(&msg.Message)
default:
return vtypes.MessageReceipt{}, big.Zero(), big.Zero(), xerrors.New("Unknown signature type")
}
// TODO: Validate the sig first
return a.applyMessage(eCtx, state, lm)
return vtypes.ApplyTipSetResult{
Receipts: receipts,
Root: a.stateWrapper.Root().String(),
}, nil
}
type randWrapper struct {
@ -108,20 +124,17 @@ func (w *randWrapper) GetRandomness(ctx context.Context, pers crypto.DomainSepar
}
type vmRand struct {
eCtx *vtypes.ExecutionContext
}
func (*vmRand) GetRandomness(ctx context.Context, dst crypto.DomainSeparationTag, h abi.ChainEpoch, input []byte) ([]byte, error) {
panic("implement me")
}
func (a *Applier) applyMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWrapper, lm types.ChainMsg) (vtypes.MessageReceipt, abi.TokenAmount, abi.TokenAmount, error) {
func (a *Applier) applyMessage(epoch abi.ChainEpoch, lm types.ChainMsg) (vtypes.MessageReceipt, abi.TokenAmount, abi.TokenAmount, error) {
ctx := context.TODO()
st := state.(*StateWrapper)
base := a.stateWrapper.Root()
base := st.Root()
randSrc := &vmRand{eCtx}
lotusVM, err := vm.NewVM(base, eCtx.Epoch, randSrc, st.bs, vdrivers.NewChainValidationSyscalls())
lotusVM, err := vm.NewVM(base, epoch, &vmRand{}, a.stateWrapper.bs, vdrivers.NewChainValidationSyscalls())
if err != nil {
return vtypes.MessageReceipt{}, big.Zero(), big.Zero(), err
}
@ -136,7 +149,7 @@ func (a *Applier) applyMessage(eCtx *vtypes.ExecutionContext, state vstate.VMWra
rval = []byte{}
}
st.stateRoot, err = lotusVM.Flush(ctx)
a.stateWrapper.stateRoot, err = lotusVM.Flush(ctx)
if err != nil {
return vtypes.MessageReceipt{}, big.Zero(), big.Zero(), err
}
@ -172,4 +185,3 @@ func toLotusSignedMsg(msg *vtypes.SignedMessage) *types.SignedMessage {
Signature: msg.Signature,
}
}
*/

View File

@ -1,6 +1,5 @@
package validation
/*
import (
"context"
@ -16,12 +15,12 @@ type Factories struct {
var _ vstate.Factories = &Factories{}
func NewFactories() *Factories {
applier := NewApplier()
return &Factories{applier}
return &Factories{}
}
func (f *Factories) NewState() vstate.VMWrapper {
return NewState()
func (f *Factories) NewStateAndApplier() (vstate.VMWrapper, vstate.Applier) {
st := NewState()
return st, NewApplier(st)
}
func (f *Factories) NewKeyManager() vstate.KeyManager {
@ -46,4 +45,3 @@ func (f *Factories) NewValidationConfig() vstate.ValidationConfig {
checkState := true
return NewConfig(trackGas, checkExit, checkRet, checkState)
}
*/

View File

@ -1,6 +1,5 @@
package validation
/*
import (
"context"
@ -11,12 +10,10 @@ import (
cbor "github.com/ipfs/go-ipld-cbor"
"golang.org/x/xerrors"
vstate "github.com/filecoin-project/chain-validation/state"
"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"
vstate "github.com/filecoin-project/chain-validation/state"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/types"
@ -61,16 +58,30 @@ func NewState() *StateWrapper {
}
}
func (s *StateWrapper) NewVM() {
return
}
func (s *StateWrapper) Root() cid.Cid {
return s.stateRoot
}
func (s *StateWrapper) Store() adt.Store {
// StoreGet the value at key from vm store
func (s *StateWrapper) StoreGet(key cid.Cid, out runtime.CBORUnmarshaler) error {
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
if err != nil {
panic(err)
return err
}
return &contextStore{tree.Store, context.Background()}
return tree.Store.Get(context.Background(), key, out)
}
// StorePut `value` into vm store
func (s *StateWrapper) StorePut(value runtime.CBORMarshaler) (cid.Cid, error) {
tree, err := state.LoadStateTree(s.cst, s.stateRoot)
if err != nil {
return cid.Undef, err
}
return tree.Store.Put(context.Background(), value)
}
func (s *StateWrapper) Actor(addr address.Address) (vstate.Actor, error) {
@ -204,4 +215,3 @@ type contextStore struct {
func (s *contextStore) Context() context.Context {
return s.ctx
}
*/

View File

@ -1,6 +1,5 @@
package vm_test
/*
import (
"fmt"
"reflect"
@ -9,6 +8,7 @@ import (
"testing"
suites "github.com/filecoin-project/chain-validation/suites"
factory "github.com/filecoin-project/lotus/chain/validation"
)
@ -67,4 +67,3 @@ func caseName(testCase suites.TestCase) string {
toks := strings.Split(fqName, ".")
return toks[len(toks)-1]
}
*/

2
extern/filecoin-ffi vendored

@ -1 +1 @@
Subproject commit 870251cd04c54e7a3a08b714f3e71a9edec28445
Subproject commit 48b8566ba12159934f3aa0a3b370e75bdb3afa0d

1
go.mod
View File

@ -12,6 +12,7 @@ require (
github.com/davidlazar/go-crypto v0.0.0-20190912175916-7055855a373f // indirect
github.com/docker/go-units v0.4.0
github.com/drand/drand v0.7.2
github.com/filecoin-project/chain-validation v0.0.6-0.20200424212533-860752305527
github.com/filecoin-project/filecoin-ffi v0.0.0-20200326153646-e899cc1dd072
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

6
go.sum
View File

@ -79,6 +79,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=
@ -128,6 +129,8 @@ 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/go.mod h1:NCEGFjcWRjb8akWFSOXvU6n2efkWIqAeOKU6o5WBGQw=
github.com/filecoin-project/chain-validation v0.0.6-0.20200424212533-860752305527 h1:g+eOYvv+UzyCWSaAvIrFWvHxFyaEI+oXsPJ1kNXxwiQ=
github.com/filecoin-project/chain-validation v0.0.6-0.20200424212533-860752305527/go.mod h1:+asFT+GUoWM3VExvjELzLqusve2s/oQcVReqz7XjR3Q=
github.com/filecoin-project/go-address v0.0.0-20191219011437-af739c490b4f/go.mod h1:rCbpXPva2NKF9/J4X6sr7hbKBgQCxyFtRj7KOZqoIms=
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=
@ -171,8 +174,6 @@ github.com/filecoin-project/sector-storage v0.0.0-20200423222053-9eb049a833b9/go
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-20200409043918-e569f4a2f504/go.mod h1:mdJraXq5vMy0+/FqVQIrnNlpQ/Em6zeu06G/ltQ0/lA=
github.com/filecoin-project/specs-actors v1.0.0/go.mod h1:nQYnFbQ7Y0bHZyq6HDEuVlCPR+U3z5Q3wMOQ+2aiV+Y=
github.com/filecoin-project/specs-actors v1.0.1-0.20200424162204-fcb213d54806 h1:nd0t/NvUFFAbml8etVqr9UHnpUib0IZuJ2eajGa0xqU=
github.com/filecoin-project/specs-actors v1.0.1-0.20200424162204-fcb213d54806/go.mod h1:nQYnFbQ7Y0bHZyq6HDEuVlCPR+U3z5Q3wMOQ+2aiV+Y=
github.com/filecoin-project/specs-actors v1.0.1-0.20200424174946-11410d0bbcaf h1:sPETeTr35OuGIgL2laDCEzB6wO+trTrw4k9vH/m82yU=
github.com/filecoin-project/specs-actors v1.0.1-0.20200424174946-11410d0bbcaf/go.mod h1:nQYnFbQ7Y0bHZyq6HDEuVlCPR+U3z5Q3wMOQ+2aiV+Y=
github.com/filecoin-project/specs-storage v0.0.0-20200410185809-9fbaaa08f275 h1:6OTcpsTQBQM0f/A67oEi4E4YtYd6fzkMqbU8cPIWMMs=
@ -241,6 +242,7 @@ github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2z
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=