Skip to content

Commit

Permalink
Fix tx parsing for placeholder actor type (#56)
Browse files Browse the repository at this point in the history
* add placeholder and ethaccount actors with evm methods

* fix placeholder and ethaccount actors on GetMetadata method

* handle placeholder actor on get actor type function
  • Loading branch information
emmanuelm41 authored Nov 20, 2023
1 parent 5852f80 commit a926c88
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 56 deletions.
20 changes: 5 additions & 15 deletions actors/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@ func (p *ActorParser) GetMetadata(txType string, msg *parser.LotusMessage, mainM
return metadata, nil, nil
}

actorCode, err := p.helper.GetActorsCache().GetActorCode(msg.To, key)
if err != nil {
return metadata, nil, err
}

c, err := cid.Parse(actorCode)
if err != nil {
p.logger.Sugar().Errorf("Could not parse actor code: %v", err)
return metadata, nil, err
}

actor, err := p.helper.GetFilecoinLib().BuiltinActors.GetActorNameFromCid(c)
actor, err := p.helper.GetActorNameFromAddress(msg.To, height, key)
if err != nil {
return metadata, nil, err
}
Expand All @@ -68,14 +57,15 @@ func (p *ActorParser) GetMetadata(txType string, msg *parser.LotusMessage, mainM
metadata, err = p.ParseReward(txType, msg, msgRct)
case manifest.VerifregKey:
metadata, err = p.ParseVerifiedRegistry(txType, msg, msgRct)
case manifest.EvmKey, manifest.EthAccountKey:
case manifest.EvmKey:
metadata, err = p.ParseEvm(txType, msg, mainMsgCid, msgRct, ethLogs)
case manifest.EamKey:
metadata, addressInfo, err = p.ParseEam(txType, msg, msgRct, mainMsgCid)
case manifest.DatacapKey:
metadata, err = p.ParseDatacap(txType, msg, msgRct)
case manifest.PlaceholderKey:
err = nil // placeholder has no methods
case manifest.PlaceholderKey, manifest.EthAccountKey:
// placeholder and ethaccount can only receive tokens by Send or InvokeEVM methods
err = nil
default:
err = parser.ErrNotValidActor
}
Expand Down
14 changes: 8 additions & 6 deletions actors/cache/actors_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,23 @@ func (a *ActorsCache) ClearBadAddressCache() {
a.badAddress.Clear()
}

func (a *ActorsCache) GetActorCode(add address.Address, key filTypes.TipSetKey) (string, error) {
func (a *ActorsCache) GetActorCode(add address.Address, key filTypes.TipSetKey, onChainOnly bool) (string, error) {
// Check if this address is flagged as bad
if a.isBadAddress(add) {
return "", fmt.Errorf("address %s is flagged as bad", add.String())
}

// Try kv store cache
actorCode, err := a.offlineCache.GetActorCode(add, key)
if err == nil {
return actorCode, nil
if !onChainOnly {
// Try kv store cache
actorCode, err := a.offlineCache.GetActorCode(add, key)
if err == nil {
return actorCode, nil
}
}

a.logger.Sugar().Debugf("[ActorsCache] - Unable to retrieve actor code from offline cache for address %s. Trying on-chain cache", add.String())
// Try on-chain cache
actorCode, err = a.onChainCache.GetActorCode(add, key)
actorCode, err := a.onChainCache.GetActorCode(add, key)
if err != nil {
a.logger.Sugar().Error("[ActorsCache] - Unable to retrieve actor code from node: %s", err.Error())
if strings.Contains(err.Error(), "actor not found") {
Expand Down
2 changes: 1 addition & 1 deletion actors/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (p *ActorParser) parseMsigParams(msg *parser.LotusMessage, height int64, ke
return "", err
}

actorCode, err := p.helper.GetActorsCache().GetActorCode(msg.To, key)
actorCode, err := p.helper.GetActorsCache().GetActorCode(msg.To, key, false)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ func (p *FilecoinParser) ParseGenesis(genesis *types.GenesisBalances, genesisTip
filAdd, _ := address.NewFromString(balance.Key)
shortAdd, _ := p.Helper.GetActorsCache().GetShortAddress(filAdd)
robustAdd, _ := p.Helper.GetActorsCache().GetRobustAddress(filAdd)
actorCode, _ := p.Helper.GetActorsCache().GetActorCode(filAdd, types2.EmptyTSK)
actorName := p.Helper.GetActorNameFromAddress(filAdd, 0, types2.EmptyTSK)
actorCode, _ := p.Helper.GetActorsCache().GetActorCode(filAdd, types2.EmptyTSK, false)
actorName, _ := p.Helper.GetActorNameFromAddress(filAdd, 0, types2.EmptyTSK)

addresses.Set(balance.Key, &types.AddressInfo{
Short: shortAdd,
Expand Down
76 changes: 44 additions & 32 deletions parser/helper/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,25 @@ import (
)

var allMethods = map[string]map[abi.MethodNum]builtin.MethodMeta{
manifest.InitKey: filInit.Methods,
manifest.CronKey: cron.Methods,
manifest.AccountKey: account.Methods,
manifest.PowerKey: power.Methods,
manifest.MinerKey: miner.Methods,
manifest.MarketKey: market.Methods,
manifest.PaychKey: paych.Methods,
manifest.MultisigKey: multisig.Methods,
manifest.RewardKey: reward.Methods,
manifest.VerifregKey: verifreg.Methods,
manifest.EvmKey: evm.Methods,
manifest.EamKey: eam.Methods,
manifest.DatacapKey: datacap.Methods,
manifest.EthAccountKey: evm.Methods, // investigate this bafy2bzacebj3i5ehw2w6veowqisj2ag4wpp25glmmfsvejbwjj2e7axavonm6
manifest.InitKey: filInit.Methods,
manifest.CronKey: cron.Methods,
manifest.AccountKey: account.Methods,
manifest.PowerKey: power.Methods,
manifest.MinerKey: miner.Methods,
manifest.MarketKey: market.Methods,
manifest.PaychKey: paych.Methods,
manifest.MultisigKey: multisig.Methods,
manifest.RewardKey: reward.Methods,
manifest.VerifregKey: verifreg.Methods,
manifest.EvmKey: evm.Methods,
manifest.EamKey: eam.Methods,
manifest.DatacapKey: datacap.Methods,

// EthAccount and Placeholder can receive tokens with Send and InvokeEVM methods
// We set evm.Methods instead of empty array of methods. Therefore, we will be able to understand
// this specific method (3844450837) - tx cid example: bafy2bzacedgmcvsp56ieciutvgwza2qpvz7pvbhhu4l5y5tdl35rwfnjn5buk
manifest.PlaceholderKey: evm.Methods,
manifest.EthAccountKey: evm.Methods,
}

type Helper struct {
Expand All @@ -70,7 +75,7 @@ func (h *Helper) GetActorAddressInfo(add address.Address, key filTypes.TipSetKey
var err error
addInfo := &types.AddressInfo{}

addInfo.ActorCid, err = h.actorCache.GetActorCode(add, key)
addInfo.ActorCid, err = h.actorCache.GetActorCode(add, key, false)
if err != nil {
h.logger.Sugar().Errorf("could not get actor code from address. Err: %s", err)
} else {
Expand Down Expand Up @@ -99,25 +104,32 @@ func (h *Helper) GetActorAddressInfo(add address.Address, key filTypes.TipSetKey
return addInfo
}

func (h *Helper) GetActorNameFromAddress(address address.Address, height int64, key filTypes.TipSetKey) string {
// Search for actor in cache
actorCode, err := h.actorCache.GetActorCode(address, key)
if err != nil {
return actors.UnknownStr
}
func (h *Helper) GetActorNameFromAddress(address address.Address, height int64, key filTypes.TipSetKey) (string, error) {
onChainOnly := false
for {
// Search for actor in cache
actorCode, err := h.actorCache.GetActorCode(address, key, onChainOnly)
if err != nil {
return actors.UnknownStr, err
}

c, err := cid.Parse(actorCode)
if err != nil {
h.logger.Sugar().Errorf("Could not parse params. Cannot cid.parse actor code: %v", err)
return actors.UnknownStr
}
c, err := cid.Parse(actorCode)
if err != nil {
h.logger.Sugar().Errorf("Could not parse params. Cannot cid.parse actor code: %v", err)
return actors.UnknownStr, err
}

actorName, err := h.lib.BuiltinActors.GetActorNameFromCid(c)
if err != nil {
return actors.UnknownStr
}
actorName, err := h.lib.BuiltinActors.GetActorNameFromCid(c)
if err != nil {
return actors.UnknownStr, err
}

return actorName
if actorName == manifest.PlaceholderKey && !onChainOnly {
onChainOnly = true
} else {
return actorName, nil
}
}
}

func (h *Helper) GetMethodName(msg *parser.LotusMessage, height int64, key filTypes.TipSetKey) (string, error) {
Expand All @@ -136,7 +148,7 @@ func (h *Helper) GetMethodName(msg *parser.LotusMessage, height int64, key filTy
return parser.MethodConstructor, nil
}

actorName := h.GetActorNameFromAddress(msg.To, height, key)
actorName, _ := h.GetActorNameFromAddress(msg.To, height, key)

actorMethods, ok := allMethods[actorName]
if !ok {
Expand Down

0 comments on commit a926c88

Please sign in to comment.