Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: transport #6276

Merged
merged 13 commits into from
Feb 28, 2024
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
3 changes: 2 additions & 1 deletion app/submodule/chain/chaininfo_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,8 @@ func (cia *chainInfoAPI) StateGetNetworkParams(ctx context.Context) (*types.Netw
UpgradeLightningHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeLightningHeight,
UpgradeThunderHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeThunderHeight,
UpgradeWatermelonHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeWatermelonHeight,
UpgradePineappleHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradePineappleHeight,
UpgradeDragonHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeDragonHeight,
UpgradePhoenixHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradePhoenixHeight,
},
Eip155ChainID: cfg.NetworkParams.Eip155ChainID,
}
Expand Down
46 changes: 42 additions & 4 deletions app/submodule/chain/miner_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (msa *minerStateAPI) StateGetAllocation(ctx context.Context, clientAddr add

st, err := view.LoadVerifregActor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load miner actor state: %v", err)
return nil, fmt.Errorf("failed to load verifreg actor state: %v", err)
}

allocation, found, err := st.GetAllocation(idAddr, allocationID)
Expand All @@ -446,6 +446,25 @@ func (msa *minerStateAPI) StateGetAllocation(ctx context.Context, clientAddr add
return allocation, nil
}

func (msa *minerStateAPI) StateGetAllAllocations(ctx context.Context, tsk types.TipSetKey) (map[types.AllocationId]types.Allocation, error) {
_, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk)
if err != nil {
return nil, fmt.Errorf("Stmgr.ParentStateViewTsk failed:%v", err)
}

st, err := view.LoadVerifregActor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load verifreg actor state: %v", err)
}

allocations, err := st.GetAllAllocations()
if err != nil {
return nil, fmt.Errorf("getting all allocations: %w", err)
}

return allocations, nil
}

// StateGetAllocations returns the all the allocations for a given client.
func (msa *minerStateAPI) StateGetAllocations(ctx context.Context, clientAddr address.Address, tsk types.TipSetKey) (map[types.AllocationId]types.Allocation, error) {
idAddr, err := msa.ChainSubmodule.API().StateLookupID(ctx, clientAddr, tsk)
Expand All @@ -460,7 +479,7 @@ func (msa *minerStateAPI) StateGetAllocations(ctx context.Context, clientAddr ad

st, err := view.LoadVerifregActor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load miner actor state: %v", err)
return nil, fmt.Errorf("failed to load verifreg actor state: %v", err)
}

allocations, err := st.GetAllocations(idAddr)
Expand All @@ -485,7 +504,7 @@ func (msa *minerStateAPI) StateGetClaim(ctx context.Context, providerAddr addres

st, err := view.LoadVerifregActor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load miner actor state: %v", err)
return nil, fmt.Errorf("failed to load verifreg actor state: %v", err)
}

claim, found, err := st.GetClaim(idAddr, claimID)
Expand Down Expand Up @@ -513,7 +532,7 @@ func (msa *minerStateAPI) StateGetClaims(ctx context.Context, providerAddr addre

st, err := view.LoadVerifregActor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load miner actor state: %v", err)
return nil, fmt.Errorf("failed to load verifreg actor state: %v", err)
}

claims, err := st.GetClaims(idAddr)
Expand All @@ -524,6 +543,25 @@ func (msa *minerStateAPI) StateGetClaims(ctx context.Context, providerAddr addre
return claims, nil
}

func (msa *minerStateAPI) StateGetAllClaims(ctx context.Context, tsk types.TipSetKey) (map[verifreg.ClaimId]verifreg.Claim, error) {
_, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk)
if err != nil {
return nil, fmt.Errorf("Stmgr.ParentStateViewTsk failed:%v", err)
}

st, err := view.LoadVerifregActor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load verifreg actor state: %v", err)
}

claims, err := st.GetAllClaims()
if err != nil {
return nil, fmt.Errorf("getting all claims: %w", err)
}

return claims, nil
}

// StateComputeDataCID computes DataCID from a set of on-chain deals
func (msa *minerStateAPI) StateComputeDataCID(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) {
nv, err := msa.API().StateNetworkVersion(ctx, tsk)
Expand Down
60 changes: 31 additions & 29 deletions app/submodule/eth/eth_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,28 +1107,28 @@ func (a *ethAPI) EthTraceBlock(ctx context.Context, blkNum string) ([]*types.Eth
return nil, fmt.Errorf("failed to get transaction hash by cid: %w", err)
}
if txHash == nil {
log.Warnf("cannot find transaction hash for cid %s", ir.MsgCid)
continue
return nil, fmt.Errorf("cannot find transaction hash for cid %s", ir.MsgCid)
}

traces := []*types.EthTrace{}
err = buildTraces(ctx, &traces, nil, []int{}, ir.ExecutionTrace, int64(ts.Height()), a.chain)
env, err := baseEnvironment(ctx, ir.Msg.From, a.chain)
if err != nil {
return nil, fmt.Errorf("failed building traces: %w", err)
return nil, fmt.Errorf("when processing message %s: %w", ir.MsgCid, err)
}

traceBlocks := make([]*types.EthTraceBlock, 0, len(traces))
for _, trace := range traces {
traceBlocks = append(traceBlocks, &types.EthTraceBlock{
err = buildTraces(env, []int{}, &ir.ExecutionTrace)
if err != nil {
return nil, fmt.Errorf("failed building traces for msg %s: %w", ir.MsgCid, err)
}

for _, trace := range env.traces {
allTraces = append(allTraces, &types.EthTraceBlock{
EthTrace: trace,
BlockHash: blkHash,
BlockNumber: int64(ts.Height()),
TransactionHash: *txHash,
TransactionPosition: msgIdx,
})
}

allTraces = append(allTraces, traceBlocks...)
}

return allTraces, nil
Expand Down Expand Up @@ -1161,34 +1161,36 @@ func (a *ethAPI) EthTraceReplayBlockTransactions(ctx context.Context, blkNum str
return nil, fmt.Errorf("failed to get transaction hash by cid: %w", err)
}
if txHash == nil {
log.Warnf("cannot find transaction hash for cid %s", ir.MsgCid)
continue
return nil, fmt.Errorf("cannot find transaction hash for cid %s", ir.MsgCid)
}

var output types.EthBytes
invokeCreateOnEAM := ir.Msg.To == builtin.EthereumAddressManagerActorAddr && (ir.Msg.Method == builtin.MethodsEAM.Create || ir.Msg.Method == builtin.MethodsEAM.Create2)
if ir.Msg.Method == builtin.MethodsEVM.InvokeContract || invokeCreateOnEAM {
output, err = decodePayload(ir.ExecutionTrace.MsgRct.Return, ir.ExecutionTrace.MsgRct.ReturnCodec)
if err != nil {
return nil, fmt.Errorf("failed to decode payload: %w", err)
env, err := baseEnvironment(ctx, ir.Msg.From, a.chain)
if err != nil {
return nil, fmt.Errorf("when processing message %s: %w", ir.MsgCid, err)
}

err = buildTraces(env, []int{}, &ir.ExecutionTrace)
if err != nil {
return nil, fmt.Errorf("failed building traces for msg %s: %w", ir.MsgCid, err)
}

var output []byte
if len(env.traces) > 0 {
switch r := env.traces[0].Result.(type) {
case *types.EthCallTraceResult:
output = r.Output
case *types.EthCreateTraceResult:
output = r.Code
}
} else {
output = encodeFilecoinReturnAsABI(ir.ExecutionTrace.MsgRct.ExitCode, ir.ExecutionTrace.MsgRct.ReturnCodec, ir.ExecutionTrace.MsgRct.Return)
}

t := types.EthTraceReplayBlockTransaction{
allTraces = append(allTraces, &types.EthTraceReplayBlockTransaction{
Output: output,
TransactionHash: *txHash,
Trace: env.traces,
StateDiff: nil,
VMTrace: nil,
}

err = buildTraces(ctx, &t.Trace, nil, []int{}, ir.ExecutionTrace, int64(ts.Height()), a.chain)
if err != nil {
return nil, fmt.Errorf("failed building traces: %w", err)
}

allTraces = append(allTraces, &t)
})
}

return allTraces, nil
Expand Down
40 changes: 40 additions & 0 deletions app/submodule/eth/eth_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package eth

import (
"bytes"
"encoding/hex"
"testing"

"github.com/ipfs/go-cid"
"github.com/multiformats/go-multicodec"
"github.com/stretchr/testify/require"
cbg "github.com/whyrusleeping/cbor-gen"

"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/venus/pkg/messagepool"
Expand Down Expand Up @@ -176,3 +179,40 @@ func TestABIEncoding(t *testing.T) {

require.Equal(t, expectedBytes, encodeAsABIHelper(22, 81, dataBytes))
}

func TestDecodePayload(t *testing.T) {
// "empty"
b, err := decodePayload(nil, 0)
require.NoError(t, err)
require.Empty(t, b)

// raw empty
_, err = decodePayload(nil, uint64(multicodec.Raw))
require.NoError(t, err)
require.Empty(t, b)

// raw non-empty
b, err = decodePayload([]byte{1}, uint64(multicodec.Raw))
require.NoError(t, err)
require.EqualValues(t, b, []byte{1})

// Invalid cbor bytes
_, err = decodePayload(nil, uint64(multicodec.DagCbor))
require.Error(t, err)

// valid cbor bytes
var w bytes.Buffer
require.NoError(t, cbg.WriteByteArray(&w, []byte{1}))
b, err = decodePayload(w.Bytes(), uint64(multicodec.DagCbor))
require.NoError(t, err)
require.EqualValues(t, b, []byte{1})

// regular cbor also works.
b, err = decodePayload(w.Bytes(), uint64(multicodec.Cbor))
require.NoError(t, err)
require.EqualValues(t, b, []byte{1})

// random codec should fail
_, err = decodePayload(w.Bytes(), 42)
require.Error(t, err)
}
Loading
Loading