Merge pull request #1329 from filecoin-project/frrist/enable-gas-tracking
Frrist/enable gas tracking
This commit is contained in:
commit
71c87ac32f
@ -39,9 +39,9 @@ func (f *Factories) NewRandomnessSource() vstate.RandomnessSource {
|
||||
}
|
||||
|
||||
func (f *Factories) NewValidationConfig() vstate.ValidationConfig {
|
||||
trackGas := false
|
||||
checkExit := false
|
||||
checkRet := false
|
||||
trackGas := true
|
||||
checkExit := true
|
||||
checkRet := false // TODO enable return value checking once https://github.com/filecoin-project/specs-actors/pull/230 lands
|
||||
// ignore gas and return value assertions
|
||||
return NewConfig(trackGas, checkExit, checkRet)
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"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"
|
||||
)
|
||||
@ -87,7 +86,8 @@ func (k *KeyManager) newBLSKey() *wallet.Key {
|
||||
// FIXME: bls needs deterministic key generation
|
||||
//sk := ffi.PrivateKeyGenerate(s.blsSeed)
|
||||
// s.blsSeed++
|
||||
sk := ffi.PrivateKeyGenerate()
|
||||
sk := [32]byte{}
|
||||
sk[0] = uint8(k.blsSeed+1) // hack to keep gas values determinist
|
||||
key, err := wallet.NewKey(types.KeyInfo{
|
||||
Type: wallet.KTBLS,
|
||||
PrivateKey: sk[:],
|
||||
|
@ -7,8 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
suites "github.com/filecoin-project/chain-validation/suites"
|
||||
"github.com/filecoin-project/chain-validation/suites/message"
|
||||
"github.com/filecoin-project/chain-validation/suites/tipset"
|
||||
|
||||
factory "github.com/filecoin-project/lotus/chain/validation"
|
||||
)
|
||||
@ -35,15 +33,7 @@ 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 incorrect implicit actor creation
|
||||
// https://filecoinproject.slack.com/archives/CHMNDCK9P/p1583358693160000
|
||||
tipset.TestInternalMessageApplicationFailure,
|
||||
/* tests to skip go here */
|
||||
}}
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ func (vmc *VMContext) ChargeGas(amount uint64) aerrors.ActorError {
|
||||
toUse := types.NewInt(amount)
|
||||
vmc.gasUsed = types.BigAdd(vmc.gasUsed, toUse)
|
||||
if vmc.gasUsed.GreaterThan(vmc.gasAvailable) {
|
||||
return aerrors.Newf(outOfGasErrCode, "not enough gas: used=%s, available=%s", vmc.gasUsed, vmc.gasAvailable)
|
||||
return aerrors.Newf(uint8(exitcode.SysErrOutOfGas), "not enough gas: used=%s, available=%s", vmc.gasUsed, vmc.gasAvailable)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -461,6 +461,20 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
serMsg, err := msg.Serialize()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("could not serialize message: %w", err)
|
||||
}
|
||||
msgGasCost := uint64(len(serMsg)) * gasPerMessageByte
|
||||
if msgGasCost > msg.GasLimit.Uint64() {
|
||||
return &ApplyRet{
|
||||
MessageReceipt: types.MessageReceipt{
|
||||
ExitCode: exitcode.SysErrOutOfGas,
|
||||
GasUsed: msg.GasLimit,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
st := vm.cstate
|
||||
if err := st.Snapshot(ctx); err != nil {
|
||||
return nil, xerrors.Errorf("snapshot failed: %w", err)
|
||||
@ -480,11 +494,6 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
||||
return nil, xerrors.Errorf("failed to look up from actor: %w", err)
|
||||
}
|
||||
|
||||
serMsg, err := msg.Serialize()
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("could not serialize message: %w", err)
|
||||
}
|
||||
msgGasCost := uint64(len(serMsg)) * gasPerMessageByte
|
||||
|
||||
gascost := types.BigMul(msg.GasLimit, msg.GasPrice)
|
||||
totalCost := types.BigAdd(gascost, msg.Value)
|
||||
|
2
go.mod
2
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.6-0.20200305211456-9486e8896d92
|
||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200305212458-670d41260fd7
|
||||
github.com/filecoin-project/filecoin-ffi v0.0.0-20200226205820-4da0bccccefb
|
||||
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
|
||||
|
4
go.sum
4
go.sum
@ -97,8 +97,8 @@ 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.6-0.20200305211456-9486e8896d92 h1:a4Vr6yy7V8n6/Vmw6g0fu9Vlf56lUy/bl4roO2Ik16E=
|
||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200305211456-9486e8896d92/go.mod h1:g9PtEzAwUNn45uM2xOWS4fUKTOFRQAFKZz2zYdKQivk=
|
||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200305212458-670d41260fd7 h1:elmXXIpuwO7UNWABiUUMISgwt8O9HkqMLKmJEzuxqR8=
|
||||
github.com/filecoin-project/chain-validation v0.0.6-0.20200305212458-670d41260fd7/go.mod h1:g9PtEzAwUNn45uM2xOWS4fUKTOFRQAFKZz2zYdKQivk=
|
||||
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=
|
||||
|
Loading…
Reference in New Issue
Block a user