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

feature: Support for multiple endpoints by chainID #189

Merged
merged 18 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9adb3ca
new networks manager to handle multiple web3 endpoint by chainID
lucasmenendez Apr 8, 2024
a248038
Merge branch 'main' into f/multiple_endpoints_by_chain
lucasmenendez Apr 8, 2024
1a2483f
replacing the horrible name NerworksManager with Web3Pool
lucasmenendez Apr 9, 2024
12aeafd
renaming networks file to web3_pool and including missing RLocks
lucasmenendez Apr 9, 2024
5a6360a
deeper integration of multiple endpoints implementing bind.ContractBa…
lucasmenendez Apr 9, 2024
875b67f
solving lll lint issue
lucasmenendez Apr 9, 2024
18e8be6
using atomic.Map to manage next available web3 endpoints to support c…
lucasmenendez Apr 10, 2024
0a6f957
Merge branch 'main' into f/multiple_endpoints_by_chain
lucasmenendez Apr 10, 2024
9b02120
debug traces removed
lucasmenendez Apr 10, 2024
485e3c7
managing available and unavailable web3 endpoints with atomics
lucasmenendez Apr 10, 2024
734dff1
limit every web3 client context timeout to 2 seconds to keep the pool…
lucasmenendez Apr 10, 2024
bd21a92
support retries in every web3 client method
lucasmenendez Apr 10, 2024
0ff59d8
Merge branch 'main' into f/multiple_endpoints_by_chain
lucasmenendez Apr 10, 2024
5a35070
token holder scan parallelized, holder providers simplifyed, fixing G…
lucasmenendez Apr 11, 2024
c0505c0
basic abstraction for endpoints pools by chain id
lucasmenendez Apr 11, 2024
ece0db5
iterator interface
lucasmenendez Apr 11, 2024
d0752b3
removing useless atomic and improving disable endpoints from pool
lucasmenendez Apr 11, 2024
4a6cee6
Merge branch 'main' into f/multiple_endpoints_by_chain
lucasmenendez Apr 11, 2024
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: 3 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Census3APIConf struct {
Port int
DataDir string
GroupKey string
Web3Providers web3.NetworkEndpoints
Web3Providers *web3.Web3Pool
HolderProviders map[uint64]providers.HolderProvider
AdminToken string
}
Expand All @@ -49,7 +49,7 @@ type census3API struct {
endpoint *api.API
censusDB *censusdb.CensusDB
queue *queue.BackgroundQueue
w3p web3.NetworkEndpoints
w3p *web3.Web3Pool
storage storagelayer.Storage
downloader *downloader.Downloader
holderProviders map[uint64]providers.HolderProvider
Expand Down Expand Up @@ -146,7 +146,7 @@ func (capi *census3API) getAPIInfo(msg *api.APIdata, ctx *httprouter.HTTPContext
info := &APIInfo{
SupportedChains: []SupportedChain{},
}
for _, provider := range capi.w3p {
for _, provider := range capi.w3p.SupportedNetworks() {
info.SupportedChains = append(info.SupportedChains, SupportedChain{
ChainID: provider.ChainID,
ShortName: provider.ShortName,
Expand Down
7 changes: 6 additions & 1 deletion cmd/census3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,15 @@ func main() {
log.Fatal("no web3 providers defined")
}
// check if the web3 providers are valid
w3p, err := web3.InitNetworkEndpoints(config.listOfWeb3Providers)
w3p, err := web3.NewWeb3Pool()
if err != nil {
log.Fatal(err)
}
for _, uri := range config.listOfWeb3Providers {
if err := w3p.AddEndpoint(uri); err != nil {
log.Fatal(err)
}
}
// init the database
database, err := db.Init(config.dataDir, "census3.sql")
if err != nil {
Expand Down
9 changes: 2 additions & 7 deletions scanner/providers/farcaster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,9 @@ func (p *FarcasterProvider) Init(iconf any) error {
}
p.contracts.lastBlock.Store(uint64(lastBlock))
// init the web3 client and contracts
currentEndpoint, exists := p.endpoints.EndpointByChainID(ChainID)
if !exists {
return errors.New("endpoint not found for the given chainID")
}
// connect to the endpoint and set the client
p.client, err = currentEndpoint.GetClient(web3.DefaultMaxWeb3ClientRetries)
p.client, err = p.endpoints.GetClient(ChainID)
if err != nil {
return errors.Join(web3.ErrConnectingToWeb3Client, fmt.Errorf("[FARCASTER]: %w", err))
return errors.Join(web3.ErrConnectingToWeb3Client, fmt.Errorf("[FARCASTER]: error getting web3 client: %w", err))
}
// parse the addresses and initialize the contracts
idRegistryAddress := common.HexToAddress(IdRegistryAddress)
Expand Down
7 changes: 3 additions & 4 deletions scanner/providers/farcaster/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"sync/atomic"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
fcir "github.com/vocdoni/census3/contracts/farcaster/idRegistry"
fckr "github.com/vocdoni/census3/contracts/farcaster/keyRegistry"
"github.com/vocdoni/census3/scanner/providers/web3"
)

type FarcasterProviderConf struct {
Endpoints web3.NetworkEndpoints
Endpoints *web3.Web3Pool
DB *DB
}

Expand All @@ -28,8 +27,8 @@ type FarcasterContracts struct {

type FarcasterProvider struct {
// web3
endpoints web3.NetworkEndpoints
client *ethclient.Client
endpoints *web3.Web3Pool
client *web3.Client
contracts FarcasterContracts
lastNetworkBlock atomic.Uint64
// db
Expand Down
10 changes: 5 additions & 5 deletions scanner/providers/web3/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ const (
)

const (
shortNameSourceUri = "https://chainid.network/chains_mini.json"
checkNetworkEndpointsTimeout = time.Second * 10
TimeLayout = "2006-01-02T15:04:05Z07:00"
shortNameSourceUri = "https://chainid.network/chains_mini.json"
checkWeb3EndpointsTimeout = time.Second * 10
TimeLayout = "2006-01-02T15:04:05Z07:00"
)

var DefaultNetworkEndpoint = &NetworkEndpoint{
var DefaultWeb3Endpoint = &Web3Endpoint{
ChainID: 11155111,
Name: "Sepolia",
ShortName: "sep",
URIs: []string{"https://rpc2.sepolia.org"},
URI: "https://rpc2.sepolia.org",
}

const (
Expand Down
199 changes: 0 additions & 199 deletions scanner/providers/web3/endpoint.go

This file was deleted.

39 changes: 0 additions & 39 deletions scanner/providers/web3/endpoint_test.go

This file was deleted.

Loading
Loading