Skip to content

Commit

Permalink
Fix: compatibility for lotus nv16 (#158)
Browse files Browse the repository at this point in the history
* Fixes to use latest rosetta-filecoin-lib

* Update mod

* Get network name from lotus api

* Disable butterfly test
  • Loading branch information
raynaudoe authored Jun 21, 2022
1 parent 9d7b95c commit 03fcc26
Show file tree
Hide file tree
Showing 17 changed files with 166 additions and 216 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
include:
- network: mainnet
url: LOTUS_RPC_URL
- network: butterfly
url: LOTUS_BUTTERFLY_RPC_URL
#- network: butterfly
# url: LOTUS_BUTTERFLY_RPC_URL
- network: calibration
url: LOTUS_CALIBRATION_RPC_URL

Expand Down
23 changes: 13 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@ require (
github.com/filecoin-project/go-data-transfer v1.15.1
github.com/filecoin-project/go-fil-markets v1.20.1
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/filecoin-project/go-state-types v0.1.7
github.com/filecoin-project/lotus v1.16.0-pre-rc
github.com/filecoin-project/specs-actors v0.9.15-0.20220514164640-94e0d5e123bd
github.com/filecoin-project/specs-actors/v8 v8.0.0-20220422153930-0afe155bfffa
github.com/filecoin-project/go-state-types v0.1.9
github.com/filecoin-project/lotus v1.16.0-rc1
github.com/filecoin-project/specs-actors v0.9.15
github.com/filecoin-project/specs-actors/v8 v8.0.0
github.com/google/uuid v1.3.0
github.com/ipfs/go-block-format v0.0.3
github.com/ipfs/go-cid v0.1.0
github.com/ipfs/go-log v1.0.5
github.com/libp2p/go-libp2p-core v0.15.1
github.com/multiformats/go-multihash v0.1.0
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6
github.com/stretchr/testify v1.7.1
github.com/zondax/rosetta-filecoin-lib v1.1501.0
github.com/zondax/filecoin-actors-cids v1.1600.0
github.com/zondax/rosetta-filecoin-lib v1.1600.1
gotest.tools v2.2.0+incompatible
)

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.0 // indirect
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/DataDog/zstd v1.5.0 // indirect
github.com/GeertJohan/go.incremental v1.0.0 // indirect
github.com/GeertJohan/go.rice v1.0.2 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
Expand Down Expand Up @@ -63,10 +66,10 @@ require (
github.com/filecoin-project/specs-actors/v2 v2.3.6 // indirect
github.com/filecoin-project/specs-actors/v3 v3.1.2 // indirect
github.com/filecoin-project/specs-actors/v4 v4.0.2 // indirect
github.com/filecoin-project/specs-actors/v5 v5.0.6-0.20220514165557-0b29a778685b // indirect
github.com/filecoin-project/specs-actors/v6 v6.0.2-0.20220511204807-569c6d12432b // indirect
github.com/filecoin-project/specs-actors/v7 v7.0.1-0.20220511223846-637436c27154 // indirect
github.com/filecoin-project/specs-storage v0.4.0 // indirect
github.com/filecoin-project/specs-actors/v5 v5.0.6 // indirect
github.com/filecoin-project/specs-actors/v6 v6.0.2 // indirect
github.com/filecoin-project/specs-actors/v7 v7.0.1 // indirect
github.com/filecoin-project/specs-storage v0.4.1 // indirect
github.com/gbrlsnchs/jwt/v3 v3.0.1 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
Expand All @@ -88,7 +91,6 @@ require (
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/icza/backscanner v0.0.0-20210726202459-ac2ffc679f94 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-block-format v0.0.3 // indirect
github.com/ipfs/go-blockservice v0.2.1 // indirect
github.com/ipfs/go-datastore v0.5.1 // indirect
github.com/ipfs/go-graphsync v0.13.1 // indirect
Expand All @@ -109,6 +111,7 @@ require (
github.com/ipfs/go-unixfs v0.3.1 // indirect
github.com/ipfs/go-verifcid v0.0.1 // indirect
github.com/ipfs/interface-go-ipfs-core v0.5.2 // indirect
github.com/ipld/go-car v0.3.3 // indirect
github.com/ipld/go-codec-dagpb v1.3.2 // indirect
github.com/ipld/go-ipld-prime v0.16.0 // indirect
github.com/ipld/go-ipld-selector-text-lite v0.0.1 // indirect
Expand Down
67 changes: 30 additions & 37 deletions go.sum

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
rosettaFilecoinLib "github.com/zondax/rosetta-filecoin-lib"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -57,8 +58,9 @@ func newBlockchainRouter(
network *types.NetworkIdentifier,
asserter *rosettaAsserter.Asserter,
api api.FullNode,
rosettaLib *rosettaFilecoinLib.RosettaConstructionFilecoin,
) http.Handler {
accountAPIService := srv.NewAccountAPIService(network, &api)
accountAPIService := srv.NewAccountAPIService(network, &api, rosettaLib)
accountAPIController := server.NewAccountAPIController(
accountAPIService,
asserter,
Expand All @@ -70,19 +72,19 @@ func newBlockchainRouter(
asserter,
)

blockAPIService := srv.NewBlockAPIService(network, &api)
blockAPIService := srv.NewBlockAPIService(network, &api, rosettaLib)
blockAPIController := server.NewBlockAPIController(
blockAPIService,
asserter,
)

mempoolAPIService := srv.NewMemPoolAPIService(network, &api)
mempoolAPIService := srv.NewMemPoolAPIService(network, &api, rosettaLib)
mempoolAPIController := server.NewMempoolAPIController(
mempoolAPIService,
asserter,
)

constructionAPIService := srv.NewConstructionAPIService(network, &api)
constructionAPIService := srv.NewConstructionAPIService(network, &api, rosettaLib)
constructionAPIController := server.NewConstructionAPIController(
constructionAPIService,
asserter,
Expand Down Expand Up @@ -113,7 +115,10 @@ func startRosettaRPC(ctx context.Context, api api.FullNode) error {
srv.Logger.Fatal(err)
}

router := newBlockchainRouter(network, asserter, api)
// Create instance of RosettaFilecoinLib for current network
r := rosettaFilecoinLib.NewRosettaConstructionFilecoin(srv.NetworkName)

router := newBlockchainRouter(network, asserter, api, r)
loggedRouter := server.LoggerMiddleware(router)
corsRouter := server.CorsMiddleware(loggedRouter)
server := &http.Server{Addr: fmt.Sprintf(":%d", ServerPort), Handler: corsRouter}
Expand Down Expand Up @@ -145,12 +150,19 @@ func connectAPI(addr string, token string) (api.FullNode, jsonrpc.ClientCloser,
return nil, nil, err
}

networkName, err := lotusAPI.StateNetworkName(context.Background())
if err != nil {
srv.Logger.Warn("Could not get Lotus network name!")
}

srv.NetworkName = string(networkName)

version, err := lotusAPI.Version(context.Background())
if err != nil {
srv.Logger.Warn("Could not get Lotus api version!")
}

srv.Logger.Info("Connected to Lotus version: ", version.String())
srv.Logger.Infof("Connected to Lotus node version: %s | Network: %s ", version.String(), srv.NetworkName)

return lotusAPI, clientCloser, nil
}
Expand Down
98 changes: 0 additions & 98 deletions rosetta/actors/actors.go

This file was deleted.

3 changes: 2 additions & 1 deletion rosetta/examples/create_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/base64"
"fmt"
"github.com/zondax/filecoin-actors-cids/utils"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -67,7 +68,7 @@ func main() {
panic("Panicking")
}

r := &rosettaFilecoinLib.RosettaConstructionFilecoin{false}
r := rosettaFilecoinLib.NewRosettaConstructionFilecoin(utils.NetworkDevnet)

gasLimit, err := strconv.ParseInt(respMetadata.Metadata[services.GasLimitKey].(string), 10, 64)
if err != nil {
Expand Down
17 changes: 10 additions & 7 deletions rosetta/services/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package services

import (
"context"
"github.com/zondax/rosetta-filecoin-proxy/rosetta/actors"
rosettaFilecoinLib "github.com/zondax/rosetta-filecoin-lib"
"github.com/zondax/rosetta-filecoin-lib/actors"
"strconv"

"github.com/coinbase/rosetta-sdk-go/server"
Expand All @@ -15,15 +16,17 @@ import (

// AccountAPIService implements the server.BlockAPIServicer interface.
type AccountAPIService struct {
network *types.NetworkIdentifier
node api.FullNode
network *types.NetworkIdentifier
node api.FullNode
rosettaLib *rosettaFilecoinLib.RosettaConstructionFilecoin
}

// NewBlockAPIService creates a new instance of a BlockAPIService.
func NewAccountAPIService(network *types.NetworkIdentifier, node *api.FullNode) server.AccountAPIServicer {
func NewAccountAPIService(network *types.NetworkIdentifier, node *api.FullNode, r *rosettaFilecoinLib.RosettaConstructionFilecoin) server.AccountAPIServicer {
return &AccountAPIService{
network: network,
node: *node,
network: network,
node: *node,
rosettaLib: r,
}
}

Expand Down Expand Up @@ -133,7 +136,7 @@ func (a AccountAPIService) AccountBalance(ctx context.Context,

if request.AccountIdentifier.SubAccount != nil {
// First, check if account is a multisig
if !actors.IsMultisigActor(actor.Code) {
if !a.rosettaLib.BuiltinActors.IsActor(actor.Code, actors.ActorMultisigName) {
return nil, BuildError(ErrAddNotMSig, nil, true)
}

Expand Down
14 changes: 11 additions & 3 deletions rosetta/services/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/ipfs/go-cid"
"github.com/stretchr/testify/mock"
"github.com/zondax/rosetta-filecoin-proxy/rosetta/actors"
"github.com/zondax/filecoin-actors-cids/utils"
rosettaFilecoinLib "github.com/zondax/rosetta-filecoin-lib"
"github.com/zondax/rosetta-filecoin-lib/actors"
"reflect"
"testing"

Expand All @@ -17,6 +19,12 @@ import (
mocks "github.com/zondax/rosetta-filecoin-proxy/rosetta/services/mocks"
)

var rosettaLib *rosettaFilecoinLib.RosettaConstructionFilecoin

func TestMain(m *testing.M) {
rosettaLib = rosettaFilecoinLib.NewRosettaConstructionFilecoin(utils.NetworkDevnet)
}

func TestAccountAPIService_AccountBalance(t *testing.T) {

nodeMock := mocks.FullNodeMock{}
Expand All @@ -40,7 +48,7 @@ func TestAccountAPIService_AccountBalance(t *testing.T) {
mockHeadTipSet := buildMockTargetTipSet(mockHeight + 10)
mockTipSetHash, _ := BuildTipSetKeyHash(mockTipSet.Key())
mockAddress := "t0128015"
mockMsigActor := buildActorMock(actors.MultisigActorCodeID, "100")
mockMsigActor := buildActorMock(rosettaLib.BuiltinActors.GetActorCid(utils.ActorsV8, actors.ActorMultisigName), "100")
///

// Output
Expand Down Expand Up @@ -240,7 +248,7 @@ func TestNewAccountAPIService(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := NewAccountAPIService(tt.args.network, tt.args.node); !reflect.DeepEqual(got, tt.want) {
if got := NewAccountAPIService(tt.args.network, tt.args.node, rosettaLib); !reflect.DeepEqual(got, tt.want) {
t.Errorf("NewAccountAPIService() = %v, want %v", got, tt.want)
}
})
Expand Down
Loading

0 comments on commit 03fcc26

Please sign in to comment.