diff --git a/src/actors/builtin/cron/cron_actor.go b/src/actors/builtin/cron/cron_actor.go index bdad42111..6da548492 100644 --- a/src/actors/builtin/cron/cron_actor.go +++ b/src/actors/builtin/cron/cron_actor.go @@ -31,11 +31,11 @@ func (a *CronActor) EpochTick(rt vmr.Runtime) vmr.InvocOutput { // a.Entries is basically a static registry for now, loaded // in the interpreter static registry. for _, entry := range a.Entries { - rt.SendCatchingErrors(&vmr.InvocInput_I{ - To_: entry.ToAddr, - Method_: entry.MethodNum, - Params_: nil, - Value_: abi.TokenAmount(0), + rt.SendCatchingErrors(vmr.InvocInput{ + To: entry.ToAddr, + Method: entry.MethodNum, + Params: nil, + Value: abi.TokenAmount(0), }) } diff --git a/src/actors/builtin/init/init_actor.go b/src/actors/builtin/init/init_actor.go index e5aa9c5f4..944e72231 100644 --- a/src/actors/builtin/init/init_actor.go +++ b/src/actors/builtin/init/init_actor.go @@ -87,11 +87,11 @@ func (a *InitActor) Exec(rt Runtime, execCodeID abi.ActorCodeID, constructorPara // Invoke constructor. If construction fails, the error should propagate and cause // Exec to fail too. - rt.SendPropagatingErrors(&vmr.InvocInput_I{ - To_: idAddr, - Method_: builtin.MethodConstructor, - Params_: constructorParams, - Value_: rt.ValueReceived(), + rt.SendPropagatingErrors(vmr.InvocInput{ + To: idAddr, + Method: builtin.MethodConstructor, + Params: constructorParams, + Value: rt.ValueReceived(), }) var addrBuf bytes.Buffer diff --git a/src/actors/builtin/storage_power/storage_power_actor.go b/src/actors/builtin/storage_power/storage_power_actor.go index 105eff244..e8078f48b 100644 --- a/src/actors/builtin/storage_power/storage_power_actor.go +++ b/src/actors/builtin/storage_power/storage_power_actor.go @@ -91,7 +91,7 @@ func (a *StoragePowerActor) CreateMiner(rt Runtime, workerAddr addr.Address, sec peerId, ), abi.TokenAmount(0), - ).ReturnValue(), + ).ReturnValue, ) autil.Assert(err == nil) diff --git a/src/actors/runtime/runtime.go b/src/actors/runtime/runtime.go new file mode 100644 index 000000000..403b85bcf --- /dev/null +++ b/src/actors/runtime/runtime.go @@ -0,0 +1,162 @@ +package runtime + +import actor "github.com/filecoin-project/specs/actors" +import abi "github.com/filecoin-project/specs/actors/abi" +import crypto "github.com/filecoin-project/specs/actors/crypto" +import exitcode "github.com/filecoin-project/specs/actors/runtime/exitcode" +import addr "github.com/filecoin-project/go-address" +import indices "github.com/filecoin-project/specs/actors/runtime/indices" +import cid "github.com/ipfs/go-cid" + +// Runtime is the VM's internal runtime object. +// this is everything that is accessible to actors, beyond parameters. +type Runtime interface { + CurrEpoch() abi.ChainEpoch + + // Randomness returns a (pseudo)random string for the given epoch and tag. + GetRandomness(epoch abi.ChainEpoch) abi.RandomnessSeed + + // The address of the immediate calling actor. + // Not necessarily the actor in the From field of the initial on-chain Message. + // Always an ID-address. + ImmediateCaller() addr.Address + ValidateImmediateCallerIs(caller addr.Address) + ValidateImmediateCallerInSet(callers []addr.Address) + ValidateImmediateCallerAcceptAnyOfType(type_ abi.ActorCodeID) + ValidateImmediateCallerAcceptAnyOfTypes(types []abi.ActorCodeID) + ValidateImmediateCallerAcceptAny() + ValidateImmediateCallerMatches(CallerPattern) + + // The address of the actor receiving the message. Always an ID-address. + CurrReceiver() addr.Address + + // The actor who mined the block in which the initial on-chain message appears. + // Always an ID-address. + ToplevelBlockWinner() addr.Address + + AcquireState() ActorStateHandle + + SuccessReturn() InvocOutput + ValueReturn([]byte) InvocOutput + + // Throw an error indicating a failure condition has occurred, from which the given actor + // code is unable to recover. + Abort(errExitCode exitcode.ExitCode, msg string) + + // Calls Abort with InvalidArguments_User. + AbortArgMsg(msg string) + AbortArg() + + // Calls Abort with InconsistentState_User. + AbortStateMsg(msg string) + AbortState() + + // Calls Abort with InsufficientFunds_User. + AbortFundsMsg(msg string) + AbortFunds() + + // Calls Abort with RuntimeAPIError. + // For internal use only (not in actor code). + AbortAPI(msg string) + + // Check that the given condition is true (and call Abort if not). + Assert(bool) + + CurrentBalance() abi.TokenAmount + ValueReceived() abi.TokenAmount + + // Look up the current values of several system-wide economic indices. + CurrIndices() indices.Indices + + // Look up the code ID of a given actor address. + GetActorCodeID(addr addr.Address) (ret abi.ActorCodeID, ok bool) + + // Run a (pure function) computation, consuming the gas cost associated with that function. + // This mechanism is intended to capture the notion of an ABI between the VM and native + // functions, and should be used for any function whose computation is expensive. + Compute(ComputeFunctionID, args []interface{}) interface{} + + // Sends a message to another actor. + // If the invoked method does not return successfully, this caller will be aborted too. + SendPropagatingErrors(input InvocInput) InvocOutput + Send( + toAddr addr.Address, + methodNum abi.MethodNum, + params abi.MethodParams, + value abi.TokenAmount, + ) InvocOutput + SendQuery( + toAddr addr.Address, + methodNum abi.MethodNum, + params abi.MethodParams, + ) []byte + SendFunds(toAddr addr.Address, value abi.TokenAmount) + + // Sends a message to another actor, trapping an unsuccessful execution. + // This may only be invoked by the singleton Cron actor. + SendCatchingErrors(input InvocInput) (output InvocOutput, exitCode exitcode.ExitCode) + + // Computes an address for a new actor. The returned address is intended to uniquely refer to + // the actor even in the event of a chain re-org (whereas an ID-address might refer to a + // different actor after messages are re-ordered). + // Always an ActorExec address. + NewActorAddress() addr.Address + + // Creates an actor in the state tree, with empty state. May only be called by InitActor. + CreateActor( + // The new actor's code identifier. + codeId abi.ActorCodeID, + // Address under which the new actor's state will be stored. Must be an ID-address. + address addr.Address, + ) + + // Deletes an actor in the state tree. May only be called by the actor itself, + // or by StoragePowerActor in the case of StorageMinerActors. + DeleteActor(address addr.Address) + + // Retrieves and deserializes an object from the store into o. Returns whether successful. + IpldGet(c cid.Cid, o interface{}) bool + // Serializes and stores an object, returning its CID. + IpldPut(x interface{}) cid.Cid + + // Provides the system call interface. + Syscalls() Syscalls +} + +type Syscalls interface { + // Verifies that a signature is valid for an address and plaintext. + VerifySignature( + signature crypto.Signature, + signer addr.Address, + plaintext []byte, + ) bool + // Computes an unsealed sector CID (CommD) from its constituent piece CIDs (CommPs) and sizes. + ComputeUnsealedSectorCID(sectorSize abi.SectorSize, pieces []abi.PieceInfo) (abi.UnsealedSectorCID, error) + // Verifies a sector seal proof. + VerifySeal(sectorSize abi.SectorSize, vi abi.SealVerifyInfo) bool + // Verifies a proof of spacetime. + VerifyPoSt(sectorSize abi.SectorSize, vi abi.PoStVerifyInfo) bool +} + +type InvocInput struct { + To addr.Address + Method abi.MethodNum + Params abi.MethodParams + Value abi.TokenAmount +} + +type InvocOutput struct { + ReturnValue []byte +} + +type ActorStateHandle interface { + UpdateRelease(newStateCID actor.ActorSubstateCID) + Release(checkStateCID actor.ActorSubstateCID) + Take() actor.ActorSubstateCID +} + +type ComputeFunctionID int64 + +const ( + Compute_VerifySignature = ComputeFunctionID(1) +) diff --git a/src/actors/runtime/runtime.id b/src/actors/runtime/runtime.id deleted file mode 100644 index 61ff335dd..000000000 --- a/src/actors/runtime/runtime.id +++ /dev/null @@ -1,158 +0,0 @@ -import actor "github.com/filecoin-project/specs/actors" -import abi "github.com/filecoin-project/specs/actors/abi" -import crypto "github.com/filecoin-project/specs/actors/crypto" -import exitcode "github.com/filecoin-project/specs/actors/runtime/exitcode" -import addr "github.com/filecoin-project/go-address" -import indices "github.com/filecoin-project/specs/actors/runtime/indices" -import cid "github.com/ipfs/go-cid" - -// Runtime is the VM's internal runtime object. -// this is everything that is accessible to actors, beyond parameters. -type Runtime interface { - CurrEpoch() abi.ChainEpoch - - // Randomness returns a (pseudo)random string for the given epoch and tag. - GetRandomness(epoch abi.ChainEpoch) abi.RandomnessSeed - - // The address of the immediate calling actor. - // Not necessarily the actor in the From field of the initial on-chain Message. - // Always an ID-address. - ImmediateCaller() addr.Address - ValidateImmediateCallerIs(caller addr.Address) - ValidateImmediateCallerInSet(callers [addr.Address]) - ValidateImmediateCallerAcceptAnyOfType(type_ abi.ActorCodeID) - ValidateImmediateCallerAcceptAnyOfTypes(types [abi.ActorCodeID]) - ValidateImmediateCallerAcceptAny() - ValidateImmediateCallerMatches(CallerPattern) - - // The address of the actor receiving the message. Always an ID-address. - CurrReceiver() addr.Address - - // The actor who mined the block in which the initial on-chain message appears. - // Always an ID-address. - ToplevelBlockWinner() addr.Address - - AcquireState() ActorStateHandle - - SuccessReturn() InvocOutput - ValueReturn(Bytes) InvocOutput - - // Throw an error indicating a failure condition has occurred, from which the given actor - // code is unable to recover. - Abort(errExitCode exitcode.ExitCode, msg string) - - // Calls Abort with InvalidArguments_User. - AbortArgMsg(msg string) - AbortArg() - - // Calls Abort with InconsistentState_User. - AbortStateMsg(msg string) - AbortState() - - // Calls Abort with InsufficientFunds_User. - AbortFundsMsg(msg string) - AbortFunds() - - // Calls Abort with RuntimeAPIError. - // For internal use only (not in actor code). - AbortAPI(msg string) - - // Check that the given condition is true (and call Abort if not). - Assert(bool) - - CurrentBalance() abi.TokenAmount - ValueReceived() abi.TokenAmount - - // Look up the current values of several system-wide economic indices. - CurrIndices() indices.Indices - - // Look up the code ID of a given actor address. - GetActorCodeID(addr addr.Address) (ret abi.ActorCodeID, ok bool) - - // Run a (pure function) computation, consuming the gas cost associated with that function. - // This mechanism is intended to capture the notion of an ABI between the VM and native - // functions, and should be used for any function whose computation is expensive. - Compute(ComputeFunctionID, args [util.Any]) util.Any - - // Sends a message to another actor. - // If the invoked method does not return successfully, this caller will be aborted too. - SendPropagatingErrors(input InvocInput) InvocOutput - Send( - toAddr addr.Address - methodNum abi.MethodNum - params abi.MethodParams - value abi.TokenAmount - ) InvocOutput - SendQuery( - toAddr addr.Address - methodNum abi.MethodNum - params abi.MethodParams - ) util.Serialization - SendFunds(toAddr addr.Address, value abi.TokenAmount) - - // Sends a message to another actor, trapping an unsuccessful execution. - // This may only be invoked by the singleton Cron actor. - SendCatchingErrors(input InvocInput) (output InvocOutput, exitCode exitcode.ExitCode) - - // Computes an address for a new actor. The returned address is intended to uniquely refer to - // the actor even in the event of a chain re-org (whereas an ID-address might refer to a - // different actor after messages are re-ordered). - // Always an ActorExec address. - NewActorAddress() addr.Address - - // Creates an actor in the state tree, with empty state. May only be called by InitActor. - CreateActor( - // The new actor's code identifier. - codeId abi.ActorCodeID - // Address under which the new actor's state will be stored. Must be an ID-address. - address addr.Address - ) - - // Deletes an actor in the state tree. May only be called by the actor itself, - // or by StoragePowerActor in the case of StorageMinerActors. - DeleteActor(address addr.Address) - - // Retrieves and deserializes an object from the store into o. Returns whether successful. - IpldGet(c cid.Cid, o interface {}) bool - // Serializes and stores an object, returning its CID. - IpldPut(x interface {}) cid.Cid - - // Provides the system call interface. - Syscalls() Syscalls -} - -type Syscalls interface { - // Verifies that a signature is valid for an address and plaintext. - VerifySignature( - signature crypto.Signature - signer addr.Address - plaintext [byte] - ) bool - // Computes an unsealed sector CID (CommD) from its constituent piece CIDs (CommPs) and sizes. - ComputeUnsealedSectorCID(sectorSize abi.SectorSize, pieces [abi.PieceInfo]) (abi.UnsealedSectorCID, error) - // Verifies a sector seal proof. - VerifySeal(sectorSize abi.SectorSize, vi abi.SealVerifyInfo) bool - // Verifies a proof of spacetime. - VerifyPoSt(sectorSize abi.SectorSize, vi abi.PoStVerifyInfo) bool -} - -type InvocInput struct { - To addr.Address - Method abi.MethodNum - Params abi.MethodParams - Value abi.TokenAmount -} - -type InvocOutput struct { - ReturnValue Bytes -} - -type ActorStateHandle interface { - UpdateRelease(newStateCID actor.ActorSubstateCID) - Release(checkStateCID actor.ActorSubstateCID) - Take() actor.ActorSubstateCID -} - -type ComputeFunctionID enum { - VerifySignature -} diff --git a/src/actors/runtime/runtime_util.go b/src/actors/runtime/runtime_util.go index d968d45a0..f3dd39665 100644 --- a/src/actors/runtime/runtime_util.go +++ b/src/actors/runtime/runtime_util.go @@ -66,17 +66,17 @@ func CallerPattern_MakeAcceptAny() CallerPattern { } func InvocInput_Make(to addr.Address, method abi.MethodNum, params abi.MethodParams, value abi.TokenAmount) InvocInput { - return &InvocInput_I{ - To_: to, - Method_: method, - Params_: params, - Value_: value, + return InvocInput{ + To: to, + Method: method, + Params: params, + Value: value, } } func InvocOutput_Make(returnValue []byte) InvocOutput { - return &InvocOutput_I{ - ReturnValue_: returnValue, + return InvocOutput{ + ReturnValue: returnValue, } } diff --git a/src/systems/filecoin_vm/interpreter/vm_interpreter.go b/src/systems/filecoin_vm/interpreter/vm_interpreter.go index 7096330db..eebc862c7 100644 --- a/src/systems/filecoin_vm/interpreter/vm_interpreter.go +++ b/src/systems/filecoin_vm/interpreter/vm_interpreter.go @@ -320,11 +320,11 @@ func _gasToFIL(gas msg.GasAmount, price abi.TokenAmount) abi.TokenAmount { } func _makeInvocInput(message msg.UnsignedMessage) vmr.InvocInput { - return &vmr.InvocInput_I{ - To_: message.To(), // Receiver address is resolved during execution. - Method_: message.Method(), - Params_: message.Params(), - Value_: message.Value(), + return vmr.InvocInput{ + To: message.To(), // Receiver address is resolved during execution. + Method: message.Method(), + Params: message.Params(), + Value: message.Value(), } } diff --git a/src/systems/filecoin_vm/runtime/impl/receipt.go b/src/systems/filecoin_vm/runtime/impl/receipt.go index 5f0580434..5b0e7bdd4 100644 --- a/src/systems/filecoin_vm/runtime/impl/receipt.go +++ b/src/systems/filecoin_vm/runtime/impl/receipt.go @@ -15,7 +15,7 @@ type MessageReceipt struct { func MessageReceipt_Make(output vmr.InvocOutput, exitCode exitcode.ExitCode, gasUsed msg.GasAmount) MessageReceipt { return MessageReceipt{ ExitCode: exitCode, - ReturnValue: output.ReturnValue(), + ReturnValue: output.ReturnValue, GasUsed: gasUsed, } } diff --git a/src/systems/filecoin_vm/runtime/impl/runtime.go b/src/systems/filecoin_vm/runtime/impl/runtime.go index e70c5e055..1b1a3f26e 100644 --- a/src/systems/filecoin_vm/runtime/impl/runtime.go +++ b/src/systems/filecoin_vm/runtime/impl/runtime.go @@ -160,7 +160,7 @@ func VMContext_Make( _valueReceived: valueReceived, _gasRemaining: gasRemaining, _numValidateCalls: 0, - _output: nil, + _output: vmr.InvocOutput{}, } } @@ -499,15 +499,15 @@ func (rtOuter *VMContext) _sendInternal(input InvocInput, errSpec ErrorHandlingS initGasRemaining := rtOuter._gasRemaining - rtOuter._rtAllocGas(gascost.InvokeMethod(input.Value(), input.Method())) + rtOuter._rtAllocGas(gascost.InvokeMethod(input.Value, input.Method)) - receiver, receiverAddr := rtOuter._resolveReceiver(input.To()) + receiver, receiverAddr := rtOuter._resolveReceiver(input.To) receiverCode, err := loadActorCode(receiver.CodeID()) if err != nil { rtOuter._throwError(exitcode.ActorCodeNotFound) } - err = rtOuter._transferFunds(rtOuter._actorAddress, receiverAddr, input.Value()) + err = rtOuter._transferFunds(rtOuter._actorAddress, receiverAddr, input.Value) if err != nil { rtOuter._throwError(exitcode.InsufficientFunds_System) } @@ -521,15 +521,15 @@ func (rtOuter *VMContext) _sendInternal(input InvocInput, errSpec ErrorHandlingS rtOuter._internalCallSeqNum+1, rtOuter._globalStatePending, receiverAddr, - input.Value(), + input.Value, rtOuter._gasRemaining, ) invocOutput, exitCode, internalCallSeqNumFinal := _invokeMethodInternal( rtInner, receiverCode, - input.Method(), - input.Params(), + input.Method, + input.Params, ) _gasAmountAssertValid(rtOuter._gasRemaining.Subtract(rtInner._gasRemaining)) @@ -625,7 +625,7 @@ func (rt *VMContext) Send( func (rt *VMContext) SendQuery(toAddr addr.Address, methodNum abi.MethodNum, params abi.MethodParams) util.Serialization { invocOutput := rt.Send(toAddr, methodNum, params, abi.TokenAmount(0)) - ret := invocOutput.ReturnValue() + ret := invocOutput.ReturnValue Assert(ret != nil) return ret } diff --git a/src/systems/filecoin_vm/runtime/impl/runtime_compute.go b/src/systems/filecoin_vm/runtime/impl/runtime_compute.go index d948563ac..32815d257 100644 --- a/src/systems/filecoin_vm/runtime/impl/runtime_compute.go +++ b/src/systems/filecoin_vm/runtime/impl/runtime_compute.go @@ -22,7 +22,7 @@ var _computeFunctionDefs = map[ComputeFunctionID]ComputeFunctionDef{} func init() { // VerifySignature - _computeFunctionDefs[vmr.ComputeFunctionID_VerifySignature] = ComputeFunctionDef{ + _computeFunctionDefs[vmr.Compute_VerifySignature] = ComputeFunctionDef{ Body: func(args []Any) Any { if len(args) != 3 { return nil