Charge sender no gas, and penalise miner for certain invalid messages
This commit is contained in:
parent
654f933d3f
commit
ad15750be3
@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
@ -185,7 +184,7 @@ type Rand interface {
|
|||||||
type ApplyRet struct {
|
type ApplyRet struct {
|
||||||
types.MessageReceipt
|
types.MessageReceipt
|
||||||
ActorErr aerrors.ActorError
|
ActorErr aerrors.ActorError
|
||||||
Penalty big.Int
|
Penalty types.BigInt
|
||||||
InternalExecutions []*ExecutionResult
|
InternalExecutions []*ExecutionResult
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,8 +287,9 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
|||||||
return &ApplyRet{
|
return &ApplyRet{
|
||||||
MessageReceipt: types.MessageReceipt{
|
MessageReceipt: types.MessageReceipt{
|
||||||
ExitCode: exitcode.SysErrOutOfGas,
|
ExitCode: exitcode.SysErrOutOfGas,
|
||||||
GasUsed: msg.GasLimit,
|
GasUsed: 0,
|
||||||
},
|
},
|
||||||
|
Penalty: types.BigMul(msg.GasPrice, types.NewInt(uint64(msgGasCost))),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,19 +301,31 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
|||||||
return &ApplyRet{
|
return &ApplyRet{
|
||||||
MessageReceipt: types.MessageReceipt{
|
MessageReceipt: types.MessageReceipt{
|
||||||
ExitCode: exitcode.SysErrActorNotFound,
|
ExitCode: exitcode.SysErrActorNotFound,
|
||||||
GasUsed: msg.GasLimit,
|
GasUsed: 0,
|
||||||
},
|
},
|
||||||
|
Penalty: types.BigMul(msg.GasPrice, types.NewInt(uint64(msgGasCost))),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
return nil, xerrors.Errorf("failed to look up from actor: %w", err)
|
return nil, xerrors.Errorf("failed to look up from actor: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !fromActor.Code.Equals(builtin.AccountActorCodeID) {
|
||||||
|
return &ApplyRet{
|
||||||
|
MessageReceipt: types.MessageReceipt{
|
||||||
|
ExitCode: exitcode.SysErrForbidden,
|
||||||
|
GasUsed: 0,
|
||||||
|
},
|
||||||
|
Penalty: types.BigMul(msg.GasPrice, types.NewInt(uint64(msgGasCost))),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
if msg.Nonce != fromActor.Nonce {
|
if msg.Nonce != fromActor.Nonce {
|
||||||
return &ApplyRet{
|
return &ApplyRet{
|
||||||
MessageReceipt: types.MessageReceipt{
|
MessageReceipt: types.MessageReceipt{
|
||||||
ExitCode: exitcode.SysErrInvalidCallSeqNum,
|
ExitCode: exitcode.SysErrInvalidCallSeqNum,
|
||||||
GasUsed: 0,
|
GasUsed: 0,
|
||||||
},
|
},
|
||||||
|
Penalty: types.BigMul(msg.GasPrice, types.NewInt(uint64(msgGasCost))),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,8 +335,9 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
|||||||
return &ApplyRet{
|
return &ApplyRet{
|
||||||
MessageReceipt: types.MessageReceipt{
|
MessageReceipt: types.MessageReceipt{
|
||||||
ExitCode: exitcode.SysErrInsufficientFunds,
|
ExitCode: exitcode.SysErrInsufficientFunds,
|
||||||
GasUsed: msg.GasLimit,
|
GasUsed: 0,
|
||||||
},
|
},
|
||||||
|
Penalty: types.BigMul(msg.GasPrice, types.NewInt(uint64(msgGasCost))),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,21 +379,19 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
|||||||
var gasUsed int64
|
var gasUsed int64
|
||||||
|
|
||||||
if errcode = aerrors.RetCode(actorErr); errcode != 0 {
|
if errcode = aerrors.RetCode(actorErr); errcode != 0 {
|
||||||
gasUsed = msg.GasLimit
|
|
||||||
// revert all state changes since snapshot
|
// revert all state changes since snapshot
|
||||||
if err := st.Revert(); err != nil {
|
if err := st.Revert(); err != nil {
|
||||||
return nil, xerrors.Errorf("revert state failed: %w", err)
|
return nil, xerrors.Errorf("revert state failed: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
gasUsed = rt.gasUsed
|
gasUsed = rt.gasUsed
|
||||||
if gasUsed < 0 {
|
if gasUsed < 0 {
|
||||||
gasUsed = 0
|
gasUsed = 0
|
||||||
}
|
}
|
||||||
// refund unused gas
|
// refund unused gas
|
||||||
refund := types.BigMul(types.NewInt(uint64(msg.GasLimit-gasUsed)), msg.GasPrice)
|
refund := types.BigMul(types.NewInt(uint64(msg.GasLimit-gasUsed)), msg.GasPrice)
|
||||||
if err := vm.transferFromGasHolder(msg.From, gasHolder, refund); err != nil {
|
if err := vm.transferFromGasHolder(msg.From, gasHolder, refund); err != nil {
|
||||||
return nil, xerrors.Errorf("failed to refund gas")
|
return nil, xerrors.Errorf("failed to refund gas")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gasReward := types.BigMul(msg.GasPrice, types.NewInt(uint64(gasUsed)))
|
gasReward := types.BigMul(msg.GasPrice, types.NewInt(uint64(gasUsed)))
|
||||||
@ -400,6 +411,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
|
|||||||
},
|
},
|
||||||
ActorErr: actorErr,
|
ActorErr: actorErr,
|
||||||
InternalExecutions: rt.internalExecutions,
|
InternalExecutions: rt.internalExecutions,
|
||||||
|
Penalty: types.NewInt(0),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user