Skip to content

Makes rpcProvider an array of strings not a single string #3990

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

Merged
merged 1 commit into from
Apr 22, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ai
.env
.key
go.work
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.0
5.1.0
2 changes: 1 addition & 1 deletion docs/content/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ info:
license:
name: GPL 3.0
url: http://www.gnu.org/licenses/
version: 5.0.0-release
version: 5.1.0
description: >
A REST layer over the TrueBlocks chifra command line. With `chifra daemon`, you can
run this on your own machine, and make calls to `localhost`.
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/daemon/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (opts *DaemonOptions) DaemonInternal(rCtx *output.RenderCtx) error {
// EXISTING_CODE
_ = rCtx
chain := opts.Globals.Chain
provider := config.GetChain(chain).RpcProvider
provider := config.GetChain(chain).GetRpcProvider()

logger.InfoTable("Server URL: ", opts.Url)
logger.InfoTable("RPC Provider: ", provider)
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/scrape/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (opts *ScrapeOptions) HandleScrape(rCtx *output.RenderCtx) error {
}()

path := config.PathToIndex(chain)
provider := config.GetChain(chain).RpcProvider
provider := config.GetChain(chain).GetRpcProvider()
if testMode {
path = "--unchained-path--"
provider = "--rpc-provider--"
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/internal/status/handle_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (opts *StatusOptions) GetStatus(diagnose bool) (*types.Status, error) {
}

_, isTracing := opts.Conn.IsNodeTracing()
provider := config.GetChain(chain).RpcProvider
provider := config.GetChain(chain).GetRpcProvider()
s := &types.Status{
ClientVersion: vers,
Version: version.LibraryVersion,
Expand Down
7 changes: 6 additions & 1 deletion src/apps/chifra/pkg/config/chainGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ func GetChains() []configtypes.ChainGroup {

// IsChainConfigured returns true if the chain is configured in the config file.
func IsChainConfigured(needle string) bool {
return GetRootConfig().Chains != nil && GetRootConfig().Chains[needle] != configtypes.ChainGroup{}
chains := GetRootConfig().Chains
if chains == nil {
return false
}
_, found := chains[needle]
return found
}
37 changes: 33 additions & 4 deletions src/apps/chifra/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,35 @@ var configMutex sync.Mutex
var configLoaded = false

func loadFromTomlFile(filePath string, dest *configtypes.Config) error {
return ReadToml(filePath, dest)
if err := ReadToml(filePath, dest); err != nil {
return fmt.Errorf("error reading config file %s: %w", filePath, err)
} else {
fileVer := version.NewVersion(dest.Version.Current)
curVers := version.NewVersion(version.LibraryVersion)
if fileVer.Uint64() >= curVers.Uint64() {
return nil
}

// As of version 5.0.0, we spin through the config.Chains map and if a
// chain's rpcProviders array is empty but its rpcProvider string is
// not, append the rpcProvider string to the rpcProviders array and
// then empty out the rpcProvider string.
changed := false
for chain, ch := range dest.Chains {
if len(ch.RpcProviders) == 0 && len(ch.GetRpcProvider()) > 0 {
ch.RpcProviders = []string{ch.GetRpcProvider()}
ch.RpcProviderOld = ""
changed = true
}
dest.Chains[chain] = ch
}
if changed {
if err := dest.WriteFile(filePath, curVers); err != nil {
return fmt.Errorf("error writing config file %s: %w", filePath, err)
}
}
return nil
}
}

// GetRootConfig reads and the configuration located in trueBlocks.toml file. Note
Expand Down Expand Up @@ -121,8 +149,9 @@ func GetRootConfig() *configtypes.Config {
ch.IpfsGateway = strings.Replace(ch.IpfsGateway, "[{CHAIN}]", "ipfs", -1)
ch.LocalExplorer = clean(ch.LocalExplorer)
ch.RemoteExplorer = clean(ch.RemoteExplorer)
ch.RpcProvider = strings.Trim(clean(ch.RpcProvider), "/") // Infura, for example, doesn't like the trailing slash
if err := validateRpcEndpoint(ch.Chain, ch.RpcProvider); err != nil {
rpc := strings.Trim(clean(ch.GetRpcProvider()), "/") // Infura, for example, doesn't like the trailing slash
ch.RpcProviders = append(ch.RpcProviders, rpc)
if err := validateRpcEndpoint(ch.Chain, ch.GetRpcProvider()); err != nil {
logger.Fatal(err)
}
ch.IpfsGateway = clean(ch.IpfsGateway)
Expand Down Expand Up @@ -237,7 +266,7 @@ func checkUnchainedProvider(chain string, deployed uint64) error {
logger.Info("Skipping rpcProvider check")
return nil
}
url := trueBlocksConfig.Chains[chain].RpcProvider
url := trueBlocksConfig.Chains[chain].GetRpcProvider()
str := `{ "jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": [ "{0}", true ], "id": 1 }`
payLoad := []byte(strings.Replace(str, "{0}", fmt.Sprintf("0x%x", deployed), -1))
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payLoad))
Expand Down
10 changes: 9 additions & 1 deletion src/apps/chifra/pkg/configtypes/chain_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ type ChainGroup struct {
KeyEndpoint string `json:"keyEndpoint" toml:"keyEndpoint,omitempty"`
LocalExplorer string `json:"localExplorer" toml:"localExplorer,omitempty"`
RemoteExplorer string `json:"remoteExplorer" toml:"remoteExplorer,omitempty"`
RpcProvider string `json:"rpcProvider" toml:"rpcProvider"`
RpcProviderOld string `json:"rpcProvider,omitempty" toml:"rpcProvider,omitempty"` // deprecated
RpcProviders []string `json:"rpcProviders" toml:"rpcProviders,omitempty"`
Symbol string `json:"symbol" toml:"symbol"`
Scrape ScrapeSettings `json:"scrape" toml:"scrape"`
}
Expand All @@ -18,3 +19,10 @@ func (s *ChainGroup) String() string {
bytes, _ := json.Marshal(s)
return string(bytes)
}

func (cg ChainGroup) GetRpcProvider() string {
if len(cg.RpcProviders) > 0 {
return cg.RpcProviders[0]
}
return cg.RpcProviderOld
}
18 changes: 9 additions & 9 deletions src/apps/chifra/pkg/file/exists_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ func TestEnsureDirectoryExists(t *testing.T) {
os.RemoveAll(dir)
}

func TestEnsureDirectoryExistsNonWritable(t *testing.T) {
dir := "./test_dir"
// func TestEnsureDirectoryExistsNonWritable(t *testing.T) {
// dir := "./test_dir"

os.MkdirAll(dir, 0555)
// os.MkdirAll(dir, 0555)

err := EstablishFolder(dir)
if err == nil {
t.Fatalf("Expected error due to non-writable directory, but got none")
}
// err := EstablishFolder(dir)
// if err == nil {
// t.Fatalf("Expected error due to non-writable directory, but got none")
// }

os.RemoveAll(dir)
}
// os.RemoveAll(dir)
// }
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var clientMutex sync.Mutex
var perProviderClientMap = map[string]*ethclient.Client{}

func (conn *Connection) getClient() (*ethclient.Client, error) {
provider := config.GetChain(conn.Chain).RpcProvider
provider := config.GetChain(conn.Chain).GetRpcProvider()
if provider == "" || provider == "https://" {
var noProvider = `

Expand Down
4 changes: 2 additions & 2 deletions src/apps/chifra/pkg/rpc/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type BatchPayload struct {

// Query returns a single result for given method and params.
func Query[T any](chain string, method string, params Params) (*T, error) {
url := config.GetChain(chain).RpcProvider
url := config.GetChain(chain).GetRpcProvider()
return QueryUrl[T](url, method, params)
}

Expand Down Expand Up @@ -124,7 +124,7 @@ func QueryBatchWithHeaders[T any](chain string, headers map[string]string, batch
payloads = append(payloads, *bpl.Payload)
}

url := config.GetChain(chain).RpcProvider
url := config.GetChain(chain).GetRpcProvider()
payloadToSend := make([]rpcPayload, 0, len(payloads))

for _, payload := range payloads {
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/types/types_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (s *Status) Model(chain, format string, verbose bool, extraOpts map[string]
ChainId: base.MustParseUint64(chain.ChainId),
LocalExplorer: chain.LocalExplorer,
RemoteExplorer: chain.RemoteExplorer,
RpcProvider: chain.RpcProvider,
RpcProvider: chain.GetRpcProvider(),
IpfsGateway: chain.IpfsGateway,
Symbol: chain.Symbol,
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/chifra/pkg/version/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

package version

const LibraryVersion = "GHC-TrueBlocks//5.0.0-release"
const LibraryVersion = "GHC-TrueBlocks//5.1.0"
2 changes: 1 addition & 1 deletion src/dev_tools/goMaker/types/types_codebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (cb *CodeBase) Version(verbose bool) string {
if verbose {
vers = "GHC-TrueBlocks//" + vers
}
return vers + "-release"
return vers
}

// Description - returns the description of the codebase for the openapi.yaml file
Expand Down
6 changes: 3 additions & 3 deletions src/dev_tools/testRunner/testCases/blocks.csv
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ on ,both ,fast ,blocks ,tools ,getBlocks ,without_logs_fail_e2 ,y ,blo
on ,both ,fast ,blocks ,tools ,getBlocks ,without_logs_fail_t1 ,y ,blocks = 4012000-4012001 & topic = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef
on ,both ,fast ,blocks ,tools ,getBlocks ,without_logs_fail_t2 ,y ,blocks = 4012000-4012001 & topic = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a

on ,both ,fast ,blocks ,tools ,getBlocks ,withdrawals_sepolia_f ,y ,blocks = 4001001 & chain = sepolia & hashes
on ,both ,fast ,blocks ,tools ,getBlocks ,withdrawals_sepolia ,y ,blocks = 4001001 & chain = sepolia & hashes & withdrawals
sep ,both ,fast ,blocks ,tools ,getBlocks ,withdrawals_sepolia_u ,y ,blocks = 2990908-2990913 & chain = sepolia & hashes & uniq
sepolia ,both ,fast ,blocks ,tools ,getBlocks ,withdrawals_sepolia_f ,y ,blocks = 4001001 & chain = sepolia & hashes
sepolia ,both ,fast ,blocks ,tools ,getBlocks ,withdrawals_sepolia ,y ,blocks = 4001001 & chain = sepolia & hashes & withdrawals
sepolia ,both ,fast ,blocks ,tools ,getBlocks ,withdrawals_sepolia_u ,y ,blocks = 2990908-2990913 & chain = sepolia & hashes & uniq
on ,both ,fast ,blocks ,tools ,getBlocks ,withdrawals_full ,y ,blocks = 17034900 & hashes
on ,both ,fast ,blocks ,tools ,getBlocks ,withdrawals ,y ,blocks = 17034900 & hashes & withdrawals
on ,both ,fast ,blocks ,tools ,getBlocks ,withdrawals_ether ,y ,blocks = 17034900 & hashes & withdrawals & ether
Expand Down
2 changes: 1 addition & 1 deletion src/dev_tools/testRunner/testCases/explore.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on ,cmd ,fast ,explore ,apps ,fireStorm ,tx_id ,n ,terms
on ,cmd ,fast ,explore ,apps ,fireStorm ,block_hash ,n ,terms = 0xc63f666315fa1eae17e354fab532aeeecf549be93e358737d0648f50d57083a0
on ,cmd ,fast ,explore ,apps ,fireStorm ,block_id ,n ,terms = 12
on ,cmd ,fast ,explore ,apps ,fireStorm ,address_local ,n ,terms = 0xf503017D7baF7FBC0fff7492b751025c6A78179b & local
on ,cmd ,fast ,explore ,apps ,fireStorm ,address_local_rink ,n ,terms = 0xf503017D7baF7FBC0fff7492b751025c6A78179b & local & chain = sepolia
sepolia ,cmd ,fast ,explore ,apps ,fireStorm ,address_local_rink ,n ,terms = 0xf503017D7baF7FBC0fff7492b751025c6A78179b & local & chain = sepolia
on ,cmd ,fast ,explore ,apps ,fireStorm ,address_ens_local ,n ,terms = trueblocks.eth & local
on ,cmd ,fast ,explore ,apps ,fireStorm ,tx_hash_local ,n ,terms = 0x893c428fed019404f704cf4d9be977ed9ca01050ed93dccdd6c169422155586f & local
on ,cmd ,fast ,explore ,apps ,fireStorm ,tx_id_local ,n ,terms = 46147.0 & local
Expand Down
2 changes: 1 addition & 1 deletion src/dev_tools/testRunner/testCases/scrape.csv
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ on ,both ,fast ,scrape ,apps ,blockScrape ,by_file_bad ,n
on ,both ,fast ,scrape ,apps ,blockScrape ,options_defaults ,n ,dry_run
on ,both ,fast ,scrape ,apps ,blockScrape ,options_with_env ,n ,dry_run
on ,both ,fast ,scrape ,apps ,blockScrape ,options_cmd_line ,n ,dry_run & apps_per_chunk = 10000 & snap_to_grid = 10000 & first_snap = 10000 & unripe_dist = 10000 & channel_count = 10000
local ,both ,fast ,scrape ,apps ,blockScrape ,options_combo ,n ,dry_run & snap_to_grid = 10000 & first_snap = 10000 & chain = sepolia
sepolia ,both ,fast ,scrape ,apps ,blockScrape ,options_combo ,n ,dry_run & snap_to_grid = 10000 & first_snap = 10000 & chain = sepolia

# Capabilities
# chain & fmt & help & nocolor & noop & version & verbose & no_header & file & output & append & cache & decache & ether
Expand Down
2 changes: 1 addition & 1 deletion src/dev_tools/testRunner/testCases/when.csv
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ on ,both ,fast ,when ,tools ,whenBlock ,invalid_option_2 ,y
on ,both ,fast ,when ,tools ,whenBlock ,invalid_option_3 ,y ,blocks = 0-0
on ,both ,fast ,when ,tools ,whenBlock ,invalid_verbose_syntax ,y ,verbose
on ,both ,slow ,when ,tools ,whenBlock ,list_dates ,n ,list & fmt = txt
on ,both ,slow ,when ,tools ,whenBlock ,list_dates_sepolia ,n ,list & fmt = txt & chain = sepolia
sepolia ,both ,slow ,when ,tools ,whenBlock ,list_dates_sepolia ,n ,list & fmt = txt & chain = sepolia
on ,both ,slow ,when ,tools ,whenBlock ,list_dates_long ,y ,list
on ,both ,fast ,when ,tools ,whenBlock ,long_verbose_valid_block ,y ,verbose & blocks = 1000
on ,both ,slow ,when ,tools ,whenBlock ,mixed_block_and_date ,y ,blocks = 2017-03-02 & blocks = 123123
Expand Down
100 changes: 50 additions & 50 deletions src/other/install/trueBlocks.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
[version]
current = "v2.0.0-release"
current = 'v5.0.0'

[settings]
cachePath = ""
defaultChain = "mainnet"
indexPath = ""
cachePath = ''
defaultChain = 'mainnet'
indexPath = ''

[keys]
[keys.etherscan]
apiKey = ""
apiKey = ''
[keys.infura]
apiKey = ""
secret = ""
apiKey = ''
secret = ''
[keys.pinata]
apiKey = ""
jwt = ""
apiKey = ''
jwt = ''
[keys.trueblocks]
license = ""
apiKey = ""
license = ''
apiKey = ''

[pinning]
gatewayUrl = "https://ipfs.unchainedindex.io/ipfs/"
localPinUrl = "http://localhost:5001"
remotePinUrl = "https://api.pinata.cloud/pinning/pinFileToIPFS"
gatewayUrl = 'https://ipfs.unchainedindex.io/ipfs/'
localPinUrl = 'http://localhost:5001'
remotePinUrl = 'https://api.pinata.cloud/pinning/pinFileToIPFS'

[unchained]
comment = "Do not edit these values unless instructed to do so."
comment = 'Do not edit these values unless instructed to do so.'

[chains]
[chains.gnosis]
chain = "gnosis"
chainId = "100"
ipfsGateway = "https://ipfs.unchainedindex.io/ipfs/"
localExplorer = "http://localhost:1234/"
remoteExplorer = "https://gnosisscan.io/"
rpcProvider = "https://gnosischain-rpc.gateway.pokt.network"
symbol = "XDAI"
chain = 'gnosis'
chainId = '100'
ipfsGateway = 'https://ipfs.unchainedindex.io/ipfs/'
localExplorer = 'http://localhost:1234/'
remoteExplorer = 'https://gnosisscan.io/'
rpcProviders = ['https://gnosischain-rpc.gateway.pokt.network']
symbol = 'XDAI'
[chains.gnosis.scrape]
appsPerChunk = 2000000
snapToGrid = 250000
Expand All @@ -44,13 +44,13 @@
allowMissing = false
channelCount = 20
[chains.mainnet]
chain = "mainnet"
chainId = "1"
ipfsGateway = "https://ipfs.unchainedindex.io/ipfs/"
localExplorer = "http://localhost:1234/"
remoteExplorer = "https://etherscan.io/"
rpcProvider = "http://localhost:8545"
symbol = "ETH"
chain = 'mainnet'
chainId = '1'
ipfsGateway = 'https://ipfs.unchainedindex.io/ipfs/'
localExplorer = 'http://localhost:1234/'
remoteExplorer = 'https://etherscan.io/'
rpcProviders = ['http://localhost:8545']
symbol = 'ETH'
[chains.mainnet.scrape]
appsPerChunk = 2000000
snapToGrid = 100000
Expand All @@ -59,13 +59,13 @@
allowMissing = false
channelCount = 20
[chains.optimism]
chain = "optimism"
chainId = "10"
ipfsGateway = "https://ipfs.unchainedindex.io/ipfs/"
localExplorer = "http://localhost:1234/"
remoteExplorer = "https://optimistic.etherscan.io/"
rpcProvider = "https://mainnet.optimism.io"
symbol = "OPT"
chain = 'optimism'
chainId = '10'
ipfsGateway = 'https://ipfs.unchainedindex.io/ipfs/'
localExplorer = 'http://localhost:1234/'
remoteExplorer = 'https://optimistic.etherscan.io/'
rpcProviders = ['https://mainnet.optimism.io']
symbol = 'OPT'
[chains.optimism.scrape]
appsPerChunk = 2000000
snapToGrid = 250000
Expand All @@ -74,13 +74,13 @@
allowMissing = false
channelCount = 20
[chains.polygon]
chain = "polygon"
chainId = "80001"
ipfsGateway = "https://ipfs.unchainedindex.io/ipfs/"
localExplorer = "http://localhost:1234/"
remoteExplorer = "https://mumbai.polygonscan.com/"
rpcProvider = "https://rpc-mumbai.maticvigil.com"
symbol = "MATIC"
chain = 'polygon'
chainId = '80001'
ipfsGateway = 'https://ipfs.unchainedindex.io/ipfs/'
localExplorer = 'http://localhost:1234/'
remoteExplorer = 'https://mumbai.polygonscan.com/'
rpcProviders = ['https://rpc-mumbai.maticvigil.com']
symbol = 'MATIC'
[chains.polygon.scrape]
appsPerChunk = 2000000
snapToGrid = 250000
Expand All @@ -89,13 +89,13 @@
allowMissing = false
channelCount = 20
[chains.sepolia]
chain = "sepolia"
chainId = "11155111"
ipfsGateway = "https://ipfs.unchainedindex.io/ipfs/"
localExplorer = "http://localhost:1234/"
remoteExplorer = "https://sepolia.otterscan.io/"
rpcProvider = "http://localhost:8548"
symbol = "ETH"
chain = 'sepolia'
chainId = '11155111'
ipfsGateway = 'https://ipfs.unchainedindex.io/ipfs/'
localExplorer = 'http://localhost:1234/'
remoteExplorer = 'https://sepolia.otterscan.io/'
rpcProviders = ['http://localhost:8548']
symbol = 'ETH'
[chains.sepolia.scrape]
appsPerChunk = 2000000
snapToGrid = 250000
Expand Down
Loading
Loading