Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions actors/actor_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
filTypes "github.com/filecoin-project/lotus/chain/types"
"github.com/ipfs/go-cid"
"github.com/zondax/fil-parser/parser"
"github.com/zondax/fil-parser/parser/helper"
"github.com/zondax/fil-parser/types"
"github.com/zondax/golem/pkg/logger"
)

type ActorParserInterface interface {
Expand All @@ -28,6 +30,10 @@ type Actor interface {
Methods(ctx context.Context, network string, height int64) (map[abi.MethodNum]nonLegacyBuiltin.MethodMeta, error)
}

// MethodNameFn is a function type that resolves method names for actor methods based on their method number,
// actor type, network parameters, and other contextual information. Allows actors to use GetMethodName without an import cycle.
type MethodNameFn func(ctx context.Context, methodNum abi.MethodNum, actorName string, height int64, network string, helper *helper.Helper, logger *logger.Logger) (string, error)

func ParseSend(msg *parser.LotusMessage) map[string]interface{} {
metadata := make(map[string]interface{})
metadata[parser.ParamsKey] = msg.Params
Expand Down
35 changes: 20 additions & 15 deletions actors/cache/actors_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ var SystemActorsId = map[string]bool{
// Check data/genesis/{network}_genesis_balances.json
var GenesisActorsId = map[string]bool{
// multisig
"f080": true,
"f090": true,
"f080": true,
// keyless account actor
"f090": true,

"f0115": true,
"f0116": true,
"f0117": true,
Expand Down Expand Up @@ -123,25 +125,26 @@ func (a *ActorsCache) ClearBadAddressCache() {
}

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

if !onChainOnly {
actorCode, err := a.offChainCache.GetActorCode(add, key, onChainOnly)
if err == nil {
return actorCode, nil
}
a.logger.Debugf("[ActorsCache] - Unable to retrieve actor code from offchain cache for address %s. Trying on-chain cache", addStr)
}

a.logger.Debugf("[ActorsCache] - Unable to retrieve actor code from offchain cache for address %s. Trying on-chain cache", add.String())
// Try on-chain cache
actorCode, err := a.onChainCache.GetActorCode(add, key, onChainOnly)
if err != nil {
a.logger.Debugf("[ActorsCache] - Unable to retrieve actor code from node: %s", err.Error())
if strings.Contains(err.Error(), "actor not found") {
a.badAddress.Set(add.String(), true)
a.badAddress.Set(addStr, true)
}

return "", err
Expand All @@ -161,18 +164,19 @@ func (a *ActorsCache) GetActorCode(add address.Address, key filTypes.TipSetKey,
}

func (a *ActorsCache) GetRobustAddress(add address.Address) (string, error) {
addStr := add.String()
// check if the address is a system actor ( no robust address)
if _, ok := SystemActorsId[add.String()]; ok {
return add.String(), nil
if _, ok := SystemActorsId[addStr]; ok {
return addStr, nil
}
// check if the address is a genesis actor ( no robust address)
if _, ok := GenesisActorsId[add.String()]; ok {
return add.String(), nil
if _, ok := GenesisActorsId[addStr]; ok {
return addStr, nil
}
// check if the address is a calibration genesis actor ( no robust address)
if tools.ParseRawNetworkName(a.networkName) == tools.CalibrationNetwork {
if _, ok := CalibrationActorsId[add.String()]; ok {
return add.String(), nil
if _, ok := CalibrationActorsId[addStr]; ok {
return addStr, nil
}
}

Expand All @@ -184,10 +188,10 @@ func (a *ActorsCache) GetRobustAddress(add address.Address) (string, error) {

// Check if this is a flagged address
if a.isBadAddress(add) {
return "", fmt.Errorf("address %s is flagged as bad", add.String())
return "", fmt.Errorf("address %s is flagged as bad", addStr)
}

a.logger.Debugf("[ActorsCache] - Unable to retrieve robust address from offchain cache for address %s. Trying on-chain cache", add.String())
a.logger.Debugf("[ActorsCache] - Unable to retrieve robust address from offchain cache for address %s. Trying on-chain cache", addStr)

// Try on-chain cache
robust, err = a.onChainCache.GetRobustAddress(add)
Expand All @@ -210,6 +214,7 @@ func (a *ActorsCache) GetRobustAddress(add address.Address) (string, error) {
}

func (a *ActorsCache) GetShortAddress(add address.Address) (string, error) {
addStr := add.String()
// Try kv store cache
short, err := a.offChainCache.GetShortAddress(add)
if err == nil {
Expand All @@ -218,10 +223,10 @@ func (a *ActorsCache) GetShortAddress(add address.Address) (string, error) {

// Check if this is a flagged address
if a.isBadAddress(add) {
return "", fmt.Errorf("address %s is flagged as bad", add.String())
return "", fmt.Errorf("address %s is flagged as bad", addStr)
}

a.logger.Debugf("[ActorsCache] - Unable to retrieve short address from offchain cache for address %s. Trying on-chain cache", add.String())
a.logger.Debugf("[ActorsCache] - Unable to retrieve short address from offchain cache for address %s. Trying on-chain cache", addStr)

// Try on-chain cache
short, err = a.onChainCache.GetShortAddress(add)
Expand Down
2 changes: 1 addition & 1 deletion actors/v2/actors.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (p *ActorParser) LatestSupportedVersion(actor string) (uint64, error) {

func (p *ActorParser) GetActor(actor string) (Actor, error) {
if strings.Contains(actor, manifest.MultisigKey) {
return multisig.New(p.helper, p.logger, p.metrics), nil
return multisig.New(p.helper, p.logger, p.metrics, GetMethodName), nil
}

return internal.GetActor(actor, p.logger, p.helper, p.metrics)
Expand Down
4 changes: 2 additions & 2 deletions actors/v2/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (i *Init) Exec(network string, height int64, msg *parser.LotusMessage, raw
createdActorCid, createdActorName, err := i.getActorDetailsFromAddress(height, version.FilNetworkVersion(), addressInfo)
if err == nil {
addressInfo.ActorCid = createdActorCid.String()
addressInfo.ActorType = parseExecActor(createdActorName)
addressInfo.ActorType = tools.ParseActorName(createdActorName)
// Store the address info in the actors cache
// if an actor is created and it's Constructor is called in the next execution,
// we will not be able to get the actor type without this.
Expand Down Expand Up @@ -147,7 +147,7 @@ func (i *Init) Exec4(network string, height int64, msg *parser.LotusMessage, raw
createdActorCid, createdActorName, err := i.getActorDetailsFromAddress(height, version.FilNetworkVersion(), addressInfo)
if err == nil {
addressInfo.ActorCid = createdActorCid.String()
addressInfo.ActorType = parseExecActor(createdActorName)
addressInfo.ActorType = tools.ParseActorName(createdActorName)
}
}

Expand Down
9 changes: 0 additions & 9 deletions actors/v2/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package init
import (
"encoding/base64"
"fmt"
"strings"

"github.com/filecoin-project/go-address"
builtinInitv10 "github.com/filecoin-project/go-state-types/builtin/v10/init"
Expand Down Expand Up @@ -163,11 +162,3 @@ func setReturnParams(msg *parser.LotusMessage, actorCID string, params typegen.C
return &types.AddressInfo{}

}

func parseExecActor(actor string) string {
s := strings.Split(actor, "/")
if len(s) < 1 {
return actor
}
return s[len(s)-1]
}
27 changes: 25 additions & 2 deletions actors/v2/multisig/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package multisig
import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"

"github.com/filecoin-project/go-address"
Expand Down Expand Up @@ -66,8 +67,9 @@ func (m *Msig) Propose(network string, msg *parser.LotusMessage, height int64, p
params := innerParams
// get ParamsKey for innerParams if possible
if innerParams != nil && innerParams[parser.ParamsKey] != nil {
if inner, ok := innerParams[parser.ParamsKey].(map[string]any); ok {
params = inner
params, err = m.paramsToMap(innerParams[parser.ParamsKey])
if err != nil {
return nil, err
}
}

Expand All @@ -93,6 +95,27 @@ func (m *Msig) Propose(network string, msg *parser.LotusMessage, height int64, p
return metadata, nil
}

func (*Msig) paramsToMap(params any) (map[string]any, error) {
dataAsMap := make(map[string]any)

tmp, err := json.Marshal(params)
if err != nil {
return nil, err
}

err = json.Unmarshal(tmp, &dataAsMap)
if err != nil {
var dataAsAny any
err = json.Unmarshal(tmp, &dataAsAny)
if err != nil {
return nil, err
}
dataAsMap[parser.ValueKey] = dataAsAny
}

return dataAsMap, nil
}

func (*Msig) RemoveSigner(network string, msg *parser.LotusMessage, height int64, key filTypes.TipSetKey, rawParams []byte) (map[string]interface{}, error) {
version := tools.VersionFromHeight(network, height)
params, ok := removeSignerParams2[version.String()]
Expand Down
17 changes: 10 additions & 7 deletions actors/v2/multisig/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ type Msig struct {
miner *miner.Miner
verifreg *verifiedRegistry.VerifiedRegistry
evm *evm.Evm

methodNameFn actors.MethodNameFn
}

func New(helper *helper.Helper, logger *logger.Logger, metrics *metrics.ActorsMetricsClient) *Msig {
func New(helper *helper.Helper, logger *logger.Logger, metrics *metrics.ActorsMetricsClient, methodNameFn actors.MethodNameFn) *Msig {
return &Msig{
helper: helper,
logger: logger,
metrics: metrics,
miner: miner.New(logger),
verifreg: verifiedRegistry.New(logger),
evm: evm.New(logger, metrics),
helper: helper,
logger: logger,
metrics: metrics,
miner: miner.New(logger),
verifreg: verifiedRegistry.New(logger),
evm: evm.New(logger, metrics),
methodNameFn: methodNameFn,
}
}

Expand Down
32 changes: 8 additions & 24 deletions actors/v2/multisig/propose.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package multisig

import (
"context"
"fmt"

"github.com/filecoin-project/go-state-types/manifest"
"strings"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/exitcode"
"github.com/filecoin-project/go-state-types/manifest"
"github.com/zondax/fil-parser/actors/v2/internal"

"github.com/filecoin-project/go-state-types/abi"
Expand Down Expand Up @@ -48,9 +47,7 @@ func (m *Msig) innerProposeParams(

// innerProposeMethod determines the actor and method name for a multisig proposal by:
// 1. Getting the actor name from the target address
// 2. Getting the appropriate actor implementation
// 3. Checking for common methods
// 4. Looking up the method name in the actor's method list
// 2. Using the methodNameFn to get the methodName from the methodNum for the actor.
func (m *Msig) innerProposeMethod(
msg *parser.LotusMessage, network string, height int64, key filTypes.TipSetKey,
) (actors.Actor, string, error) {
Expand All @@ -59,31 +56,18 @@ func (m *Msig) innerProposeMethod(
return nil, "", err
}
var actor actors.Actor
actor = m
if actorName != manifest.MultisigKey {
if strings.Contains(actorName, manifest.MultisigKey) {
actor = m
} else {
actor, err = internal.GetActor(actorName, m.logger, m.helper, m.metrics)
if err != nil {
return nil, "", err
}
}

method, err := m.helper.CheckCommonMethods(msg, height, key)
methodName, err := m.methodNameFn(context.Background(), msg.Method, actorName, height, network, m.helper, m.logger)
if err != nil {
return nil, "", err
}
if method != "" {
return actor, method, nil
}

actorMethods, err := actor.Methods(context.Background(), network, height)
if err != nil {
return nil, "", err
}

proposeMethod, ok := actorMethods[msg.Method]
if !ok {
return nil, "", fmt.Errorf("unrecognized propose method: %s for actor %s", method, actorName)
}

return actor, proposeMethod.Name, nil
return actor, methodName, nil
}
10 changes: 10 additions & 0 deletions actors/v2/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ import (
)

func GetMethodName(ctx context.Context, methodNum abi.MethodNum, actorName string, height int64, network string, helper *helper.Helper, logger *logger.Logger) (string, error) {
// Shortcut 1 - Method "0" corresponds to "MethodSend"
if methodNum == 0 {
return parser.MethodSend, nil
}

// Shortcut 2 - Method "1" corresponds to "MethodConstructor"
if methodNum == 1 {
return parser.MethodConstructor, nil
}

actorMethods, err := ActorMethods(ctx, actorName, height, network, helper, logger)
if err != nil {
return "", err
Expand Down
Loading