Skip to content

Commit c55979b

Browse files
klemenfnmbobenvidbregar-flare
authored
V0.1.42 upgrade
* Upgrade to avalanche rosetta v0.1.42 * Support go-flare v1.11.13 * Update localflare CI tests * Add a docker compose and script for easy localflare testing --------- Co-authored-by: Marko Boben <marko.boben@gmail.com> Co-authored-by: Vid Bregar <vid@flare.network>
1 parent 14c6c14 commit c55979b

File tree

155 files changed

+21213
-2337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+21213
-2337
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,25 @@ jobs:
1717
outputs:
1818
IMAGE_TAG: ${{ steps.ct_image_tag.outputs.IMAGE_TAG }}
1919
IMAGE_PATH_0: ghcr.io/${{ github.repository }}
20+
ROSETTA_BRANCH: ${{ steps.ct_image_tag.outputs.ROSETTA_BRANCH }}
2021
steps:
2122
- uses: actions/checkout@v3
2223
with:
2324
fetch-depth: 0
2425
- id: ct_image_tag
2526
run: |
26-
TAG_NORMALIZED=$(echo ${GITHUB_REF#refs/*/} | sed "s/[^[:alpha:]0-9.-]/-/g")
27+
# For pull requests, use GITHUB_HEAD_REF (source branch of PR)
28+
# For push events, extract branch name from GITHUB_REF
29+
if [ -n "$GITHUB_HEAD_REF" ]; then
30+
BRANCH_NAME=$GITHUB_HEAD_REF
31+
else
32+
BRANCH_NAME=${GITHUB_REF#refs/*/}
33+
fi
34+
TAG_NORMALIZED=$(echo "$BRANCH_NAME" | sed "s/[^[:alpha:]0-9.-]/-/g")
2735
if [[ "$TAG_NORMALIZED" == "main" ]]; then echo "IMAGE_TAG=latest" >> $GITHUB_OUTPUT
2836
else echo "IMAGE_TAG=$TAG_NORMALIZED" >> $GITHUB_OUTPUT
2937
fi
38+
echo "ROSETTA_BRANCH=$BRANCH_NAME" >> $GITHUB_OUTPUT
3039
3140
build-container:
3241
runs-on: ubuntu-latest
@@ -49,7 +58,7 @@ jobs:
4958
- name: Build and push container image
5059
shell: bash
5160
run: |
52-
docker build --progress=plain --no-cache --build-arg ROSETTA_SRC=. --tag ${{ needs.define-env.outputs.IMAGE_PATH_0 }}:${{ needs.define-env.outputs.IMAGE_TAG }} -f ./server/Dockerfile .
61+
docker build --progress=plain --no-cache --build-arg ROSETTA_SRC=. --build-arg ROSETTA_BRANCH=${{ needs.define-env.outputs.ROSETTA_BRANCH }} --tag ${{ needs.define-env.outputs.IMAGE_PATH_0 }}:${{ needs.define-env.outputs.IMAGE_TAG }} -f ./server/Dockerfile .
5362
docker push ${{ needs.define-env.outputs.IMAGE_PATH_0 }}:${{ needs.define-env.outputs.IMAGE_TAG }}
5463
- name: get image sha256
5564
id: image_sha256
@@ -58,135 +67,39 @@ jobs:
5867
export IMAGE_SHA256_0_FULL=$(docker image inspect --format='{{json .RepoDigests}}' ${{ needs.define-env.outputs.IMAGE_PATH_0 }}:${{ needs.define-env.outputs.IMAGE_TAG }} | jq --raw-output '.[0]')
5968
echo "IMAGE_SHA256_0=${IMAGE_SHA256_0_FULL#*@}" >> $GITHUB_OUTPUT
6069
61-
62-
test-container-localflare-online:
70+
test-localflare:
6371
runs-on: ubuntu-latest
6472
needs:
6573
- build-container
6674
- define-env
67-
strategy:
68-
fail-fast: false
69-
matrix:
70-
index: [1, 2, 3, 4, 5]
71-
START_ROSETTA_SERVER_AFTER_BOOTSTRAP: [true, false]
72-
services:
73-
flare_node:
74-
image: ${{ needs.define-env.outputs.IMAGE_PATH_0 }}@${{ needs.build-container.outputs.IMAGE_SHA256_0 }}
75-
ports:
76-
- 9650:9650
77-
- 9651:9651
78-
- 8080:8080
79-
env:
80-
DEBUG: true
81-
NETWORK_ID: localflare
82-
FLARE_LOCAL_TXS_ENABLED: true
83-
START_ROSETTA_SERVER_AFTER_BOOTSTRAP: ${{ matrix.START_ROSETTA_SERVER_AFTER_BOOTSTRAP }}
84-
EXTRA_ARGUMENTS: --staking-tls-cert-file=/app/flare/staking/local/staker1.crt --staking-tls-key-file=/app/flare/staking/local/staker1.key
85-
options: >-
86-
--health-interval 15s
87-
--health-timeout 15s
88-
--health-retries 10
89-
--health-start-period 30s
9075
steps:
9176
- uses: actions/checkout@v3
77+
9278
- uses: actions/setup-go@v3
9379
with:
9480
go-version: ${{ env.go_version }}
95-
- run: sudo apt update -y && sudo apt install curl -y
96-
97-
- name: Wait for go-flare to bind to port
98-
shell: bash
99-
run: curl -s --retry 6 --retry-delay 10 --retry-connrefused http://localhost:9650 || exit 1
100-
101-
- name: Import testnet
102-
shell: bash
103-
run: |
104-
curl -s -o /tmp/test_pchain_import.sh https://raw.githubusercontent.com/flare-foundation/go-flare/114017731f4f8f6192a4df2748da914c0257e16b/avalanchego/scripts/test_pchain_import.sh
105-
sed -i 's/localhost/127.0.0.1/g' /tmp/test_pchain_import.sh
106-
sed -i 's/ | jq .//g' /tmp/test_pchain_import.sh
107-
bash /tmp/test_pchain_import.sh
108-
while [[ "$(curl -X POST --data '{ "jsonrpc": "2.0", "method": "platform.getHeight", "params": {}, "id": 1 }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/P | jq -r .result.height)" != "2" ]]
109-
do
110-
echo "Block height not reached.. Block Height:" $(curl -X POST --data '{ "jsonrpc": "2.0", "method": "platform.getHeight", "params": {}, "id": 1 }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/P | jq -r .result.height)
111-
sleep 1
112-
done
113-
- name: Wait for rosetta to bind to port
114-
shell: bash
115-
run: curl -s --retry 6 --retry-delay 10 --retry-connrefused http://localhost:8080 || exit 1
116-
117-
- name: List networks Rosetta API lists
118-
shell: bash
119-
run: |
120-
curl -s --location --request POST 'http://127.0.0.1:8080/network/list' \
121-
--header 'Content-Type: application/json' \
122-
--data-raw '{ "metadata" : {} }' \
123-
--fail || exit 1
124-
- name: Install rosetta cli
125-
shell: bash
126-
run: |
127-
mkdir -p /tmp/rosetta
128-
curl -o /tmp/rosetta/install.sh -sSfL https://raw.githubusercontent.com/coinbase/mesh-cli/refs/tags/v0.10.4/scripts/install.sh
129-
sed -i 's/REPO="rosetta-cli"/REPO="mesh-cli"/g' /tmp/rosetta/install.sh
130-
bash /tmp/rosetta/install.sh -b /tmp/rosetta/ v0.10.4
131-
- name: Run rosetta-cli check:construction
132-
timeout-minutes: 5
133-
shell: bash
134-
run: |
135-
pushd server/rosetta-cli-conf/localflare
136-
/tmp/rosetta/rosetta-cli --configuration-file=./config.json check:construction
137-
popd
13881

82+
- name: Set up Docker Compose
83+
uses: docker/setup-compose-action@v1
13984

140-
141-
test-container-localflare-offline:
142-
runs-on: ubuntu-latest
143-
needs:
144-
- build-container
145-
- define-env
146-
strategy:
147-
fail-fast: false
148-
matrix:
149-
index: [1, 2, 3, 4, 5]
150-
services:
151-
flare_node:
152-
image: ${{ needs.define-env.outputs.IMAGE_PATH_0 }}@${{ needs.build-container.outputs.IMAGE_SHA256_0 }}
153-
ports:
154-
- 9650:9650
155-
- 9651:9651
156-
- 8080:8080
157-
env:
158-
DEBUG: true
159-
NETWORK_ID: localflare
160-
FLARE_LOCAL_TXS_ENABLED: true
161-
MODE: offline
162-
EXTRA_ARGUMENTS: --staking-tls-cert-file=/app/flare/staking/local/staker1.crt --staking-tls-key-file=/app/flare/staking/local/staker1.key
163-
options: >-
164-
--health-interval 15s
165-
--health-timeout 15s
166-
--health-retries 10
167-
--health-start-period 30s
168-
steps:
169-
- uses: actions/checkout@v3
170-
- uses: actions/setup-go@v3
85+
- uses: actions/setup-node@v6
17186
with:
172-
go-version: ${{ env.go_version }}
173-
- run: sudo apt update -y && sudo apt install curl -y
87+
node-version: 20
17488

175-
- name: Wait for rosetta to bind to port
176-
shell: bash
177-
run: curl -s --retry 6 --retry-delay 10 --retry-connrefused http://localhost:8080 || exit 1
89+
- run: sudo apt update -y && sudo apt install curl jq -y
17890

179-
- name: List networks Rosetta API lists
91+
- name: Install yarn
92+
run: npm install -g yarn
93+
94+
- name: Run localflare test script
95+
env:
96+
CI: true
97+
ROSETTA_IMAGE: ${{ needs.define-env.outputs.IMAGE_PATH_0 }}@${{ needs.build-container.outputs.IMAGE_SHA256_0 }}
98+
START_ROSETTA_SERVER_AFTER_BOOTSTRAP: true
99+
MODE: online
180100
shell: bash
181101
run: |
182-
curl -s --location --request POST 'http://127.0.0.1:8080/network/list' \
183-
--header 'Content-Type: application/json' \
184-
--data-raw '{ "metadata" : {} }' \
185-
--fail || exit 1
186-
187-
188-
189-
102+
./test-localflare.sh
190103
191104
test-make_build:
192105
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ data
2121
__debug_bin*
2222
build_docker.sh
2323
.idea
24+
tmp/

server/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM golang:1.22 AS flare
55

66
WORKDIR /app
77

8-
ARG GO_FLARE_VERSION=v1.11.0
8+
ARG GO_FLARE_VERSION=v1.11.13-rc0
99
ARG GO_FLARE_REPO=https://github.com/flare-foundation/go-flare
1010

1111
RUN git clone --branch "$GO_FLARE_VERSION" "${GO_FLARE_REPO}" .
@@ -20,8 +20,9 @@ RUN cd avalanchego && \
2020
# ------------------------------------------------------------------------------
2121
FROM golang:1.22 AS rosetta
2222

23-
ARG ROSETTA_SRC=https://github.com/flare-foundation/flare-rosetta/archive/refs/heads/main.zip
24-
ARG ROSETTA_SRC_ZIP_SUBFOLDER=flare-rosetta-main
23+
ARG ROSETTA_BRANCH=main
24+
ARG ROSETTA_SRC=https://github.com/flare-foundation/flare-rosetta/archive/refs/heads/${ROSETTA_BRANCH}.zip
25+
ARG ROSETTA_SRC_ZIP_SUBFOLDER=flare-rosetta-${ROSETTA_BRANCH}
2526

2627
WORKDIR /tmp
2728

server/client/client.go

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,54 @@ package client
22

33
import (
44
"context"
5-
"github.com/ava-labs/avalanchego/ids"
6-
"github.com/ava-labs/avalanchego/network/peer"
7-
"github.com/ava-labs/avalanchego/utils/json"
85
"math/big"
96
"strings"
107

118
"github.com/ava-labs/avalanchego/api/info"
9+
"github.com/ava-labs/avalanchego/ids"
1210
"github.com/ava-labs/avalanchego/utils/rpc"
13-
ethtypes "github.com/ava-labs/coreth/core/types"
11+
"github.com/ava-labs/coreth/core/types"
1412
"github.com/ava-labs/coreth/interfaces"
15-
ethcommon "github.com/ethereum/go-ethereum/common"
13+
"github.com/ava-labs/coreth/plugin/evm"
14+
"github.com/ethereum/go-ethereum/common"
15+
16+
"github.com/ava-labs/avalanche-rosetta/constants"
1617
)
1718

1819
// Interface compliance
1920
var _ Client = &client{}
2021

2122
type Client interface {
22-
IsBootstrapped(context.Context, string, ...rpc.Option) (bool, error)
23+
// info.Client methods
24+
InfoClient
25+
2326
ChainID(context.Context) (*big.Int, error)
24-
BlockByHash(context.Context, ethcommon.Hash) (*ethtypes.Block, error)
25-
BlockByNumber(context.Context, *big.Int) (*ethtypes.Block, error)
26-
HeaderByHash(context.Context, ethcommon.Hash) (*ethtypes.Header, error)
27-
HeaderByNumber(context.Context, *big.Int) (*ethtypes.Header, error)
28-
TransactionByHash(context.Context, ethcommon.Hash) (*ethtypes.Transaction, bool, error)
29-
TransactionReceipt(context.Context, ethcommon.Hash) (*ethtypes.Receipt, error)
27+
BlockByHash(context.Context, common.Hash) (*types.Block, error)
28+
BlockByNumber(context.Context, *big.Int) (*types.Block, error)
29+
HeaderByHash(context.Context, common.Hash) (*types.Header, error)
30+
HeaderByNumber(context.Context, *big.Int) (*types.Header, error)
31+
TransactionByHash(context.Context, common.Hash) (*types.Transaction, bool, error)
32+
TransactionReceipt(context.Context, common.Hash) (*types.Receipt, error)
3033
TraceTransaction(context.Context, string) (*Call, []*FlatCall, error)
3134
TraceBlockByHash(context.Context, string) ([]*Call, [][]*FlatCall, error)
32-
SendTransaction(context.Context, *ethtypes.Transaction) error
33-
BalanceAt(context.Context, ethcommon.Address, *big.Int) (*big.Int, error)
34-
NonceAt(context.Context, ethcommon.Address, *big.Int) (uint64, error)
35+
SendTransaction(context.Context, *types.Transaction) error
36+
BalanceAt(context.Context, common.Address, *big.Int) (*big.Int, error)
37+
NonceAt(context.Context, common.Address, *big.Int) (uint64, error)
3538
SuggestGasPrice(context.Context) (*big.Int, error)
3639
EstimateGas(context.Context, interfaces.CallMsg) (uint64, error)
3740
TxPoolContent(context.Context) (*TxPoolContent, error)
38-
GetNetworkName(context.Context, ...rpc.Option) (string, error)
39-
Peers(context.Context, ...rpc.Option) ([]info.Peer, error)
40-
// Peers_v1_11 enables info.peers RPC call compatible with v1.11.
41-
// Once the dependencies are upgraded, this should be replaced with Peers.
42-
Peers_v1_11(context.Context, []ids.NodeID, ...rpc.Option) ([]Peer_v1_11, error)
43-
GetContractInfo(ethcommon.Address, bool) (string, uint8, error)
41+
GetContractInfo(common.Address, bool) (string, uint8, error)
4442
CallContract(context.Context, interfaces.CallMsg, *big.Int) ([]byte, error)
43+
IssueTx(ctx context.Context, txBytes []byte, options ...rpc.Option) (ids.ID, error)
44+
GetAtomicUTXOs(ctx context.Context, addrs []ids.ShortID, sourceChain string, limit uint32, startAddress ids.ShortID, startUTXOID ids.ID, options ...rpc.Option) ([][]byte, ids.ShortID, ids.ID, error)
45+
EstimateBaseFee(ctx context.Context) (*big.Int, error)
4546
}
4647

47-
type clientFix struct {
48-
requester rpc.EndpointRequester
49-
}
50-
51-
func newClientFix(uri string) *clientFix {
52-
return &clientFix{
53-
requester: rpc.NewEndpointRequester(
54-
uri+"/ext/info",
55-
"info",
56-
),
57-
}
58-
}
59-
60-
type Peer_v1_11 struct {
61-
peer.Info
62-
63-
Benched []string `json:"benched"`
64-
}
65-
66-
type PeersReply_v1_11 struct {
67-
// Number of elements in [Peers]
68-
NumPeers json.Uint64 `json:"numPeers"`
69-
// Each element is a peer
70-
Peers []Peer_v1_11 `json:"peers"`
71-
}
72-
73-
func (cf *clientFix) Peers_v1_11(ctx context.Context, nodeIDs []ids.NodeID, options ...rpc.Option) ([]Peer_v1_11, error) {
74-
res := &PeersReply_v1_11{}
75-
err := cf.requester.SendRequest(ctx, "peers", &info.PeersArgs{
76-
NodeIDs: nodeIDs,
77-
}, res, options...)
78-
return res.Peers, err
79-
}
48+
type EvmClient evm.Client
8049

8150
type client struct {
8251
info.Client
83-
*clientFix
52+
EvmClient
8453
*EthClient
8554
*ContractClient
8655
}
@@ -94,10 +63,10 @@ func NewClient(ctx context.Context, endpoint string) (Client, error) {
9463
return nil, err
9564
}
9665

97-
return client{
66+
return &client{
9867
Client: info.NewClient(endpoint),
99-
clientFix: newClientFix(endpoint),
68+
EvmClient: evm.NewClient(endpoint, constants.CChain.String()),
10069
EthClient: eth,
10170
ContractClient: NewContractClient(eth.Client),
10271
}, nil
103-
}
72+
}

server/client/contract.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,28 @@ const (
1313
// ContractClient is a client for the calling contract information
1414
type ContractClient struct {
1515
ethClient ethclient.Client
16-
cache *cache.LRU
16+
cache *cache.LRU[common.Address, *ContractInfo]
17+
}
18+
19+
type ContractInfo struct {
20+
Symbol string
21+
Decimals uint8
1722
}
1823

1924
// NewContractClient returns a new ContractInfo client
2025
func NewContractClient(c ethclient.Client) *ContractClient {
2126
return &ContractClient{
2227
ethClient: c,
23-
cache: &cache.LRU{Size: contractCacheSize},
28+
cache: &cache.LRU[common.Address, *ContractInfo]{Size: contractCacheSize},
2429
}
2530
}
2631

2732
// GetContractInfo returns the symbol and decimals for [addr].
2833
func (c *ContractClient) GetContractInfo(addr common.Address, erc20 bool) (string, uint8, error) {
2934
// We don't define another struct because this is never used outside of this
3035
// function.
31-
type ContractInfo struct {
32-
Symbol string
33-
Decimals uint8
34-
}
35-
3636
if currency, cached := c.cache.Get(addr); cached {
37-
cast := currency.(*ContractInfo)
38-
return cast.Symbol, cast.Decimals, nil
37+
return currency.Symbol, currency.Decimals, nil
3938
}
4039

4140
token, err := NewContractInfoToken(addr, c.ethClient)

server/client/eth.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package client
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/ava-labs/coreth/eth/tracers"
87
"github.com/ava-labs/coreth/ethclient"
@@ -24,7 +23,7 @@ type EthClient struct {
2423

2524
// NewEthClient returns a new EVM client
2625
func NewEthClient(ctx context.Context, endpoint string) (*EthClient, error) {
27-
endpointURL := fmt.Sprintf("%s%s", endpoint, prefixEth)
26+
endpointURL := endpoint + prefixEth
2827

2928
c, err := rpc.DialContext(ctx, endpointURL)
3029
if err != nil {

0 commit comments

Comments
 (0)