Skip to content

Commit

Permalink
Merge pull request #1429 from filecoin-project/asr/NAA
Browse files Browse the repository at this point in the history
Calculate new actor addresses as per updated spec
  • Loading branch information
whyrusleeping authored Mar 20, 2020
2 parents e4c1625 + 56f1680 commit ecc8f60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
12 changes: 8 additions & 4 deletions chain/vm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -166,14 +165,15 @@ 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())
if err != nil {
rt.Abortf(exitcode.ErrSerialization, "create actor address: %v", err)
}

rt.incrementNumActorsCreated()
return addr
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++
}
16 changes: 8 additions & 8 deletions chain/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ecc8f60

Please sign in to comment.