Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
Add gas to test vm (#1408)
Browse files Browse the repository at this point in the history
* Add gas to test vm

- introduce runtime.Pricelist - the price list interface
- copy current filecoin pricelist to testing package
- charge for gas
- return (and ignore) gas used from ApplyMessage
- setup large default gas limit
- handle out of gas aborts

Co-authored-by: ZenGround0 <ZenGround0@users.noreply.github.com>
  • Loading branch information
ZenGround0 and ZenGround0 authored May 19, 2021
1 parent 5114581 commit 6ed06ce
Show file tree
Hide file tree
Showing 11 changed files with 791 additions and 64 deletions.
4 changes: 2 additions & 2 deletions actors/test/commit_post_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ func TestCommitPoStFlow(t *testing.T) {
ChainCommitRand: []byte("not really random"),
}
// PoSt is rejected for skipping all sectors.
_, code := tv.ApplyMessage(addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.SubmitWindowedPoSt, &submitParams)
assert.Equal(t, exitcode.ErrIllegalArgument, code)
result := tv.ApplyMessage(addrs[0], minerAddrs.RobustAddress, big.Zero(), builtin.MethodsMiner.SubmitWindowedPoSt, &submitParams)
assert.Equal(t, exitcode.ErrIllegalArgument, result.Code)

vm.ExpectInvocation{
To: minerAddrs.IDAddress,
Expand Down
12 changes: 7 additions & 5 deletions actors/test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ func publishDeal(t *testing.T, v *vm.VM, provider, dealClient, minerID addr.Addr

publishDealParams := market.PublishStorageDealsParams{
Deals: []market.ClientDealProposal{{
Proposal: deal,
ClientSignature: crypto.Signature{},
Proposal: deal,
ClientSignature: crypto.Signature{
Type: crypto.SigTypeBLS,
},
}},
}
ret, code := v.ApplyMessage(provider, builtin.StorageMarketActorAddr, big.Zero(), builtin.MethodsMarket.PublishStorageDeals, &publishDealParams)
require.Equal(t, exitcode.Ok, code)
result := v.ApplyMessage(provider, builtin.StorageMarketActorAddr, big.Zero(), builtin.MethodsMarket.PublishStorageDeals, &publishDealParams)
require.Equal(t, exitcode.Ok, result.Code)

expectedPublishSubinvocations := []vm.ExpectInvocation{
{To: minerID, Method: builtin.MethodsMiner.ControlAddresses, SubInvocations: []vm.ExpectInvocation{}},
Expand All @@ -62,5 +64,5 @@ func publishDeal(t *testing.T, v *vm.VM, provider, dealClient, minerID addr.Addr
SubInvocations: expectedPublishSubinvocations,
}.Matches(t, v.LastInvocation())

return ret.(*market.PublishStorageDealsReturn)
return result.Ret.(*market.PublishStorageDealsReturn)
}
12 changes: 6 additions & 6 deletions actors/test/multisig_delete_self_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func TestMultisigDeleteSelf2Of3RemovedIsProposer(t *testing.T) {
vm.ApplyOk(t, v, addrs[1], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)

// txnid not found when third approval gets processed indicating that the transaction has gone through successfully
_, code := v.ApplyMessage(addrs[2], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)
assert.Equal(t, exitcode.ErrNotFound, code)
result := v.ApplyMessage(addrs[2], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)
assert.Equal(t, exitcode.ErrNotFound, result.Code)

}

Expand Down Expand Up @@ -115,8 +115,8 @@ func TestMultisigDeleteSelf2Of3RemovedIsApprover(t *testing.T) {
vm.ApplyOk(t, v, addrs[0], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)

// txnid not found when third approval gets processed indicating that the transaction has gone through successfully
_, code := v.ApplyMessage(addrs[2], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)
assert.Equal(t, exitcode.ErrNotFound, code)
result := v.ApplyMessage(addrs[2], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)
assert.Equal(t, exitcode.ErrNotFound, result.Code)

}

Expand Down Expand Up @@ -165,8 +165,8 @@ func TestMultisigDeleteSelf2Of2(t *testing.T) {
vm.ApplyOk(t, v, addrs[1], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)

// txnid not found when another approval gets processed indicating that the transaction has gone through successfully
_, code := v.ApplyMessage(addrs[1], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)
assert.Equal(t, exitcode.ErrNotFound, code)
result := v.ApplyMessage(addrs[1], multisigAddr, big.Zero(), builtin.MethodsMultisig.Approve, &approveRemoveSignerParams)
assert.Equal(t, exitcode.ErrNotFound, result.Code)
}

func TestMultisigSwapsSelf2Of3(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/filecoin-project/specs-actors/v5/actors/builtin/system"
"github.com/filecoin-project/specs-actors/v5/actors/builtin/verifreg"
"github.com/filecoin-project/specs-actors/v5/actors/util/smoothing"
"github.com/filecoin-project/specs-actors/v5/support/vm"
)

func main() {
Expand Down Expand Up @@ -233,4 +234,10 @@ func main() {
panic(err)
}

if err := gen.WriteTupleEncodersToFile("./support/vm/cbor_gen.go", "vm",
vm.ChainMessage{},
); err != nil {
panic(err)
}

}
5 changes: 3 additions & 2 deletions support/agent/deal_client_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package agent

import (
"crypto/sha256"
mh "github.com/multiformats/go-multihash"
"math/bits"
"math/rand"
"strconv"

mh "github.com/multiformats/go-multihash"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
Expand Down Expand Up @@ -170,7 +171,7 @@ func (dca *DealClientAgent) createDeal(s SimState, provider DealProvider) error

provider.CreateDeal(market.ClientDealProposal{
Proposal: proposal,
ClientSignature: crypto.Signature{},
ClientSignature: crypto.Signature{Type: crypto.SigTypeBLS},
})
dca.DealCount++
return nil
Expand Down
23 changes: 11 additions & 12 deletions support/agent/sim.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ func (s *Sim) Tick() error {

// run messages
for _, msg := range blockMessages {
ret, code := s.v.ApplyMessage(msg.From, msg.To, msg.Value, msg.Method, msg.Params)
result := s.v.ApplyMessage(msg.From, msg.To, msg.Value, msg.Method, msg.Params)

// for now, assume everything should work
if code != exitcode.Ok {
return errors.Errorf("exitcode %d: message failed: %v\n%s\n", code, msg, strings.Join(s.v.GetLogs(), "\n"))
if result.Code != exitcode.Ok {
return errors.Errorf("exitcode %d: message failed: %v\n%s\n", result.Code, msg, strings.Join(s.v.GetLogs(), "\n"))
}

if msg.ReturnHandler != nil {
if err := msg.ReturnHandler(s, msg, ret); err != nil {
if err := msg.ReturnHandler(s, msg, result.Ret); err != nil {
return err
}
}
Expand All @@ -185,9 +185,9 @@ func (s *Sim) Tick() error {
}

// run cron
_, code := s.v.ApplyMessage(builtin.SystemActorAddr, builtin.CronActorAddr, big.Zero(), builtin.MethodsCron.EpochTick, nil)
if code != exitcode.Ok {
return errors.Errorf("exitcode %d: cron message failed:\n%s\n", code, strings.Join(s.v.GetLogs(), "\n"))
result := s.v.ApplyMessage(builtin.SystemActorAddr, builtin.CronActorAddr, big.Zero(), builtin.MethodsCron.EpochTick, nil)
if result.Code != exitcode.Ok {
return errors.Errorf("exitcode %d: cron message failed:\n%s\n", result.Code, strings.Join(s.v.GetLogs(), "\n"))
}

// store last stats
Expand Down Expand Up @@ -315,9 +315,9 @@ func (s *Sim) rewardMiner(addr address.Address, wins uint64) error {
GasReward: big.Zero(),
WinCount: int64(wins),
}
_, code := s.v.ApplyMessage(builtin.SystemActorAddr, builtin.RewardActorAddr, big.Zero(), builtin.MethodsReward.AwardBlockReward, &rewardParams)
if code != exitcode.Ok {
return errors.Errorf("exitcode %d: reward message failed:\n%s\n", code, strings.Join(s.v.GetLogs(), "\n"))
result := s.v.ApplyMessage(builtin.SystemActorAddr, builtin.RewardActorAddr, big.Zero(), builtin.MethodsReward.AwardBlockReward, &rewardParams)
if result.Code != exitcode.Ok {
return errors.Errorf("exitcode %d: reward message failed:\n%s\n", result.Code, strings.Join(s.v.GetLogs(), "\n"))
}
return nil
}
Expand Down Expand Up @@ -441,7 +441,7 @@ type PowerTable struct {

// VM interface allowing a simulation to operate over multiple VM versions
type SimVM interface {
ApplyMessage(from, to address.Address, value abi.TokenAmount, method abi.MethodNum, params interface{}) (cbor.Marshaler, exitcode.ExitCode)
ApplyMessage(from, to address.Address, value abi.TokenAmount, method abi.MethodNum, params interface{}) vm.MessageResult
GetCirculatingSupply() abi.TokenAmount
GetLogs() []string
GetState(addr address.Address, out cbor.Unmarshaler) error
Expand All @@ -458,7 +458,6 @@ type SimVM interface {
}

var _ SimVM = (*vm.VM)(nil)
var _ SimVM = (*vm2.VM)(nil)

type SimMinerState interface {
HasSectorNo(adt.Store, abi.SectorNumber) (bool, error)
Expand Down
Loading

0 comments on commit 6ed06ce

Please sign in to comment.