Calculate new actor addresses as per updated spec

This commit is contained in:
Aayush Rajasekaran 2020-03-20 15:43:08 -04:00
parent 7b69697439
commit ef288b8a6c
2 changed files with 16 additions and 12 deletions

View File

@ -44,8 +44,7 @@ type Runtime struct {
originNonce uint64
internalExecutions []*ExecutionResult
// the first internal call has a value of 1 for this field
internalCallCounter int64
numActorsCreated uint64
}
func (rs *Runtime) ResolveAddress(address address.Address) (ret address.Address, ok bool) {
@ -166,7 +165,7 @@ func (rt *Runtime) NewActorAddress() address.Address {
if err := binary.Write(&b, binary.BigEndian, rt.originNonce); err != nil {
rt.Abortf(exitcode.ErrSerialization, "writing nonce address into a buffer: %v", err)
}
if err := binary.Write(&b, binary.BigEndian, rt.internalCallCounter); err != nil { // TODO: expose on vm
if err := binary.Write(&b, binary.BigEndian, rt.numActorsCreated); err != nil { // TODO: expose on vm
rt.Abortf(exitcode.ErrSerialization, "writing callSeqNum address into a buffer: %v", err)
}
addr, err := address.NewActorAddress(b.Bytes())
@ -174,6 +173,7 @@ func (rt *Runtime) NewActorAddress() address.Address {
rt.Abortf(exitcode.ErrSerialization, "create actor address: %v", err)
}
rt.incrementNumActorsCreated()
return addr
}
@ -340,7 +340,7 @@ func (rt *Runtime) internalSend(to address.Address, method abi.MethodNum, value
if subrt != nil {
er.Subcalls = subrt.internalExecutions
rt.internalCallCounter = subrt.internalCallCounter
rt.numActorsCreated = subrt.numActorsCreated
}
rt.internalExecutions = append(rt.internalExecutions, &er)
return ret, errSend
@ -438,3 +438,7 @@ func (rt *Runtime) chargeGasSafe(toUse int64) aerrors.ActorError {
func (rt *Runtime) Pricelist() Pricelist {
return rt.pricelist
}
func (rt *Runtime) incrementNumActorsCreated() {
rt.numActorsCreated++
}

View File

@ -115,7 +115,7 @@ func (bs *gasChargingBlocks) Put(blk block.Block) error {
return nil
}
func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin address.Address, originNonce uint64, usedGas int64, icc int64) *Runtime {
func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin address.Address, originNonce uint64, usedGas int64, nac uint64) *Runtime {
rt := &Runtime{
ctx: ctx,
vm: vm,
@ -125,10 +125,10 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, origin addres
originNonce: originNonce,
height: vm.blockHeight,
gasUsed: usedGas,
gasAvailable: msg.GasLimit,
internalCallCounter: icc,
pricelist: PricelistByEpoch(vm.blockHeight),
gasUsed: usedGas,
gasAvailable: msg.GasLimit,
numActorsCreated: nac,
pricelist: PricelistByEpoch(vm.blockHeight),
}
rt.cst = &cbor.BasicIpldStore{
Blocks: &gasChargingBlocks{rt.ChargeGas, rt.pricelist, vm.cst.Blocks},
@ -216,14 +216,14 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
origin := msg.From
on := msg.Nonce
var icc int64 = 0
var nac uint64 = 0
if parent != nil {
gasUsed = parent.gasUsed + gasUsed
origin = parent.origin
on = parent.originNonce
icc = parent.internalCallCounter + 1
nac = parent.numActorsCreated
}
rt := vm.makeRuntime(ctx, msg, origin, on, gasUsed, icc)
rt := vm.makeRuntime(ctx, msg, origin, on, gasUsed, nac)
if parent != nil {
defer func() {
parent.gasUsed = rt.gasUsed