From 6594b03be13b3c81e3b9567904df2bc84fb59598 Mon Sep 17 00:00:00 2001 From: Ran Mishael Date: Tue, 17 Dec 2024 18:59:45 +0100 Subject: [PATCH 1/7] fix spec issues --- scripts/useful_commands.sh | 55 ++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/scripts/useful_commands.sh b/scripts/useful_commands.sh index 28578374e9..8df9542a48 100755 --- a/scripts/useful_commands.sh +++ b/scripts/useful_commands.sh @@ -172,41 +172,62 @@ echo "---------------------------------------------" get_base_specs() { local priority_specs=( - "./specs/mainnet-1/specs/ibc.json" - "./specs/mainnet-1/specs/cosmoswasm.json" - "./specs/mainnet-1/specs/tendermint.json" - "./specs/mainnet-1/specs/cosmossdk.json" - "./specs/mainnet-1/specs/cosmossdkv45.json" - "./specs/mainnet-1/specs/cosmossdkv50.json" - "./specs/mainnet-1/specs/ethermint.json" - "./specs/mainnet-1/specs/ethereum.json" - "./specs/mainnet-1/specs/solana.json" + "specs/mainnet-1/specs/ibc.json" + "specs/mainnet-1/specs/cosmoswasm.json" + "specs/mainnet-1/specs/tendermint.json" + "specs/mainnet-1/specs/cosmossdk.json" + "specs/testnet-2/specs/cosmossdkv45.json" + "specs/mainnet-1/specs/cosmossdkv50.json" + "specs/mainnet-1/specs/ethermint.json" + "specs/mainnet-1/specs/ethereum.json" + "specs/mainnet-1/specs/solana.json" + "specs/mainnet-1/specs/aptos.json" ) (IFS=,; echo "${priority_specs[*]}") } get_all_specs() { - local priority_specs=($(get_base_specs)) # Ensure it's an array + # Ensure get_base_specs outputs elements correctly split into an array + IFS=',' read -r -a priority_specs <<< "$(get_base_specs)" + local other_specs=() - + + # Find all JSON spec files and store them in a temporary file find specs/{mainnet-1,testnet-2}/specs -name "*.json" > /tmp/specs_list.txt - + + # Process each file from the find command while IFS= read -r file; do local is_priority=false + local is_in_other_specs=false + + # Check if the file is in priority_specs for pspec in "${priority_specs[@]}"; do - if [[ "./$file" == "$pspec" ]]; then + if [[ "$file" == "$pspec" ]]; then is_priority=true break fi done - + + # Check if the file is already in other_specs if [[ "$is_priority" == "false" ]]; then + for ospec in "${other_specs[@]}"; do + if [[ "$file" == "$ospec" ]]; then + is_in_other_specs=true + break + fi + done + fi + + # Add the file to other_specs if it's not already there + if [[ "$is_priority" == "false" && "$is_in_other_specs" == "false" ]]; then other_specs+=("$file") fi done < /tmp/specs_list.txt - + + # Cleanup temporary file rm /tmp/specs_list.txt - + + # Combine arrays and output as a comma-separated string (IFS=,; echo "${priority_specs[*]},${other_specs[*]}") -} \ No newline at end of file +} From 33d1c67a8e9253edec49c7d6429138168f0c3ff0 Mon Sep 17 00:00:00 2001 From: Ran Mishael Date: Wed, 18 Dec 2024 16:05:56 +0100 Subject: [PATCH 2/7] Working starknet spec --- .../strk_addon_example_with_root.yml | 8 + .../strk_addon_example_with_ws.yml | 12 + protocol/chainlib/chain_fetcher.go | 1 + protocol/chainlib/chain_router.go | 18 +- protocol/chainlib/chainproxy/connector.go | 3 +- protocol/chainlib/jsonRPC.go | 12 + .../init_starknet_addons_only_with_node.sh | 2 +- specs/mainnet-1/specs/starknet.json | 268 ++++++++++++++---- 8 files changed, 255 insertions(+), 69 deletions(-) create mode 100644 config/provider_examples/strk_addon_example_with_root.yml create mode 100644 config/provider_examples/strk_addon_example_with_ws.yml diff --git a/config/provider_examples/strk_addon_example_with_root.yml b/config/provider_examples/strk_addon_example_with_root.yml new file mode 100644 index 0000000000..da105d09e5 --- /dev/null +++ b/config/provider_examples/strk_addon_example_with_root.yml @@ -0,0 +1,8 @@ +endpoints: + - api-interface: jsonrpc + chain-id: STRK + network-address: + address: "127.0.0.1:2220" + node-urls: + - url: wss://starknet-mainnet.domain.com/ws/XXX + - url: https://starknet-mainnet.domain.com/XXX diff --git a/config/provider_examples/strk_addon_example_with_ws.yml b/config/provider_examples/strk_addon_example_with_ws.yml new file mode 100644 index 0000000000..e21f1525cc --- /dev/null +++ b/config/provider_examples/strk_addon_example_with_ws.yml @@ -0,0 +1,12 @@ +endpoints: + - api-interface: jsonrpc + chain-id: STRK + network-address: + address: "127.0.0.1:2220" + node-urls: + - url: wss://starknet-mainnet.domain.com/ws/XXX/rpc/v0_7 + internal-path: /ws/rpc/v0_7 + - url: wss://starknet-mainnet.domain.com/ws/XXX/rpc/v0_6 + internal-path: /ws/rpc/v0_6 + - url: wss://starknet-mainnet.domain.com/ws/XXX + - url: https://starknet-mainnet.domain.com/XXX diff --git a/protocol/chainlib/chain_fetcher.go b/protocol/chainlib/chain_fetcher.go index 920cab724b..5a6ca38362 100644 --- a/protocol/chainlib/chain_fetcher.go +++ b/protocol/chainlib/chain_fetcher.go @@ -215,6 +215,7 @@ func (cf *ChainFetcher) Verify(ctx context.Context, verification VerificationCon return utils.LavaFormatWarning("[-] verify failed to parse result", err, utils.LogAttr("chain_id", chainId), utils.LogAttr("Api_interface", cf.endpoint.ApiInterface), + utils.LogAttr("function_template", parsing.FunctionTemplate), ) } diff --git a/protocol/chainlib/chain_router.go b/protocol/chainlib/chain_router.go index 9c07a6bdbb..bbef0ccb6e 100644 --- a/protocol/chainlib/chain_router.go +++ b/protocol/chainlib/chain_router.go @@ -189,8 +189,8 @@ func (cri *chainRouterImpl) BatchNodeUrlsByServices(rpcProviderEndpoint lavasess routerKey.SetExtensions(nodeUrl.Addons) } - _, isAlreadyAutoGenerated := autoGeneratedInternalPaths[nodeUrl.InternalPath] - cri.setRouterKeyInBatch(nodeUrl, returnedBatch, routerKey, rpcProviderEndpoint, isAlreadyAutoGenerated) // will override existing entries + // _, isAlreadyAutoGenerated := autoGeneratedInternalPaths[nodeUrl.InternalPath] + cri.setRouterKeyInBatch(nodeUrl, returnedBatch, routerKey, rpcProviderEndpoint, true) // will override existing entries if nodeUrl.InternalPath == "" { // root path if !isWs { @@ -222,20 +222,10 @@ func (cri *chainRouterImpl) BatchNodeUrlsByServices(rpcProviderEndpoint lavasess } func (*chainRouterImpl) setRouterKeyInBatch(nodeUrl common.NodeUrl, returnedBatch map[string]lavasession.RPCProviderEndpoint, routerKey lavasession.RouterKey, rpcProviderEndpoint lavasession.RPCProviderEndpoint, overrideExistingEntry bool) { - // if the router key does not exit, create it anyway - // if we need to override, override + // if the router key does not exist, create it anyway // if it exists and we should not override, add the node url to the existing list routerKeyString := routerKey.String() - if existingEndpoint, ok := returnedBatch[routerKeyString]; ok && !overrideExistingEntry { - // setting the incoming url first as it might be http while existing is websocket. (we prioritize http over ws when possible) - returnedBatch[routerKeyString] = lavasession.RPCProviderEndpoint{ - NetworkAddress: rpcProviderEndpoint.NetworkAddress, - ChainID: rpcProviderEndpoint.ChainID, - ApiInterface: rpcProviderEndpoint.ApiInterface, - Geolocation: rpcProviderEndpoint.Geolocation, - NodeUrls: append([]common.NodeUrl{nodeUrl}, existingEndpoint.NodeUrls...), - } - + if _, ok := returnedBatch[routerKeyString]; ok && !overrideExistingEntry { return } diff --git a/protocol/chainlib/chainproxy/connector.go b/protocol/chainlib/chainproxy/connector.go index c6926a0cb0..fd6066a268 100644 --- a/protocol/chainlib/chainproxy/connector.go +++ b/protocol/chainlib/chainproxy/connector.go @@ -11,6 +11,7 @@ import ( "crypto/x509" "encoding/hex" "errors" + "fmt" "log" "os" "strconv" @@ -66,7 +67,7 @@ func NewConnector(ctx context.Context, nConns uint, nodeUrl common.NodeUrl) (*Co rpcClient, err := connector.createConnection(ctx, nodeUrl, connector.numberOfFreeClients()) if err != nil { - return nil, utils.LavaFormatError("Failed to create the first connection", err, utils.Attribute{Key: "address", Value: nodeUrl.UrlStr()}) + return nil, fmt.Errorf("Failed to create the first connection: %w, url: %s", err, nodeUrl.UrlStr()) } connector.addClient(rpcClient) diff --git a/protocol/chainlib/jsonRPC.go b/protocol/chainlib/jsonRPC.go index de48263375..8e9ab86c7f 100644 --- a/protocol/chainlib/jsonRPC.go +++ b/protocol/chainlib/jsonRPC.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "strconv" + "strings" "time" "github.com/goccy/go-json" @@ -563,6 +564,17 @@ func NewJrpcChainProxy(ctx context.Context, nConns uint, rpcProviderEndpoint lav func (cp *JrpcChainProxy) start(ctx context.Context, nConns uint, nodeUrl common.NodeUrl) error { conn, err := chainproxy.NewConnector(ctx, nConns, nodeUrl) if err != nil { + isWs, parseErr := IsUrlWebSocket(nodeUrl.Url) + if parseErr == nil && isWs { + newUrl := strings.TrimSuffix(nodeUrl.Url, "/") + "/ws" + utils.LavaFormatWarning("Failed creating connector for ws, trying to create with /ws path", err, utils.LogAttr("url", nodeUrl.UrlStr()), utils.LogAttr("newUrl", newUrl)) + nodeUrl.Url = newUrl + conn, newConnErr := chainproxy.NewConnector(ctx, nConns, nodeUrl) + if newConnErr == nil { + cp.conn = conn + return nil + } + } return err } diff --git a/scripts/pre_setups/init_starknet_addons_only_with_node.sh b/scripts/pre_setups/init_starknet_addons_only_with_node.sh index dd47128009..fd023a7e7b 100755 --- a/scripts/pre_setups/init_starknet_addons_only_with_node.sh +++ b/scripts/pre_setups/init_starknet_addons_only_with_node.sh @@ -43,7 +43,7 @@ PROVIDER1_LISTENER="127.0.0.1:2220" lavad tx subscription buy DefaultPlan $(lavad keys show user1 -a) -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE wait_next_block -lavad tx pairing stake-provider "STRK" $PROVIDERSTAKE "$PROVIDER1_LISTENER,1 $PROVIDER1_LISTENER,1,trace" 1 $(operator_address) -y --from servicer1 --provider-moniker "dummyMoniker" --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE +lavad tx pairing stake-provider "STRK" $PROVIDERSTAKE "$PROVIDER1_LISTENER,1" 1 $(operator_address) -y --from servicer1 --provider-moniker "dummyMoniker" --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE lavad tx project set-policy $(lavad keys show user1 -a)-admin ./cookbook/projects/policy_all_chains_with_addon.yml -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE sleep_until_next_epoch diff --git a/specs/mainnet-1/specs/starknet.json b/specs/mainnet-1/specs/starknet.json index 1b0dea991c..4fce368698 100644 --- a/specs/mainnet-1/specs/starknet.json +++ b/specs/mainnet-1/specs/starknet.json @@ -20,10 +20,10 @@ }, "api_collections": [ { - "enabled": true, + "enabled": false, "collection_data": { "api_interface": "jsonrpc", - "internal_path": "", + "internal_path": "HTTP-ONLY", "type": "POST", "add_on": "" }, @@ -598,17 +598,87 @@ "expected_value": "*" } ] + } + ] + }, + { + "enabled": false, + "collection_data": { + "api_interface": "jsonrpc", + "internal_path": "WS-ONLY", + "type": "POST", + "add_on": "" + }, + "apis": [ + { + "name": "pathfinder_subscribe", + "block_parsing": { + "parser_arg": [ + "latest" + ], + "parser_func": "DEFAULT" + }, + "compute_units": 1000, + "enabled": true, + "category": { + "deterministic": false, + "local": true, + "subscription": true, + "stateful": 0 + }, + "extra_compute_units": 0 }, { - "name": "pruning", - "parse_directive": { - "function_tag": "GET_BLOCK_BY_NUM" + "name": "pathfinder_unsubscribe", + "block_parsing": { + "parser_arg": [ + "latest" + ], + "parser_func": "DEFAULT" }, - "values": [ - { - "expected_value": "1" - } - ] + "compute_units": 10, + "enabled": true, + "category": { + "deterministic": false, + "local": true, + "subscription": true, + "stateful": 0 + }, + "extra_compute_units": 0 + } + ], + "parse_directives": [ + { + "function_tag": "SUBSCRIBE", + "api_name": "pathfinder_subscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"pathfinder_unsubscribe\",\"params\":[%s],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "pathfinder_unsubscribe" + } + ] + }, + { + "enabled": true, + "collection_data": { + "api_interface": "jsonrpc", + "internal_path": "", + "type": "POST", + "add_on": "" + }, + "inheritance_apis": [ + { + "api_interface": "jsonrpc", + "internal_path": "HTTP-ONLY", + "type": "POST", + "add_on": "" + }, + { + "api_interface": "jsonrpc", + "internal_path": "WS-ONLY", + "type": "POST", + "add_on": "" } ] }, @@ -623,7 +693,7 @@ "inheritance_apis": [ { "api_interface": "jsonrpc", - "internal_path": "", + "internal_path": "HTTP-ONLY", "type": "POST", "add_on": "" } @@ -640,7 +710,30 @@ "inheritance_apis": [ { "api_interface": "jsonrpc", - "internal_path": "", + "internal_path": "HTTP-ONLY", + "type": "POST", + "add_on": "" + } + ] + }, + { + "enabled": true, + "collection_data": { + "api_interface": "jsonrpc", + "internal_path": "/ws/rpc/v0_6", + "type": "POST", + "add_on": "" + }, + "inheritance_apis": [ + { + "api_interface": "jsonrpc", + "internal_path": "/rpc/v0_6", + "type": "POST", + "add_on": "" + }, + { + "api_interface": "jsonrpc", + "internal_path": "WS-ONLY", "type": "POST", "add_on": "" } @@ -657,7 +750,7 @@ "inheritance_apis": [ { "api_interface": "jsonrpc", - "internal_path": "", + "internal_path": "HTTP-ONLY", "type": "POST", "add_on": "" } @@ -667,20 +760,43 @@ "enabled": true, "collection_data": { "api_interface": "jsonrpc", - "internal_path": "/rpc/pathfinder/v0.1", + "internal_path": "/ws/rpc/v0_7", "type": "POST", "add_on": "" }, + "inheritance_apis": [ + { + "api_interface": "jsonrpc", + "internal_path": "/rpc/v0_7", + "type": "POST", + "add_on": "" + }, + { + "api_interface": "jsonrpc", + "internal_path": "WS-ONLY", + "type": "POST", + "add_on": "" + } + ] + }, + { + "enabled": true, + "collection_data": { + "api_interface": "jsonrpc", + "internal_path": "", + "type": "POST", + "add_on": "trace" + }, "apis": [ { - "name": "pathfinder_version", + "name": "starknet_traceTransaction", "block_parsing": { "parser_arg": [ "latest" ], "parser_func": "DEFAULT" }, - "compute_units": 10, + "compute_units": 100, "enabled": true, "category": { "deterministic": true, @@ -691,14 +807,15 @@ "extra_compute_units": 0 }, { - "name": "pathfinder_getProof", + "name": "starknet_simulateTransactions", "block_parsing": { "parser_arg": [ - "latest" + "0" ], - "parser_func": "DEFAULT" + "parser_func": "PARSE_BY_ARG", + "encoding": "base64" }, - "compute_units": 10, + "compute_units": 100, "enabled": true, "category": { "deterministic": true, @@ -709,14 +826,16 @@ "extra_compute_units": 0 }, { - "name": "pathfinder_getTransactionStatus", + "name": "starknet_traceBlockTransactions", "block_parsing": { "parser_arg": [ - "latest" + "0" ], - "parser_func": "DEFAULT" + "parser_func": "PARSE_BY_ARG", + "encoding": "base64" }, - "compute_units": 10, + "compute_units": 1000, + "timeout_ms": 20000, "enabled": true, "category": { "deterministic": true, @@ -731,20 +850,20 @@ { "name": "enabled", "parse_directive": { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"pathfinder_version\",\"params\":[],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"starknet_traceBlockTransactions\",\"params\":[\"latest\"],\"id\":1}", "function_tag": "VERIFICATION", "result_parsing": { "parser_arg": [ - "latest" + "0" ], - "parser_func": "DEFAULT" + "parser_func": "PARSE_BY_ARG", + "encoding": "base64" }, - "api_name": "pathfinder_version" + "api_name": "starknet_traceBlockTransactions" }, "values": [ { - "expected_value": "*", - "severity": "Warning" + "expected_value": "*" } ] } @@ -754,20 +873,20 @@ "enabled": true, "collection_data": { "api_interface": "jsonrpc", - "internal_path": "", + "internal_path": "/rpc/pathfinder/v0.1", "type": "POST", - "add_on": "trace" + "add_on": "" }, "apis": [ { - "name": "starknet_traceTransaction", + "name": "pathfinder_version", "block_parsing": { "parser_arg": [ "latest" ], "parser_func": "DEFAULT" }, - "compute_units": 100, + "compute_units": 10, "enabled": true, "category": { "deterministic": true, @@ -778,15 +897,14 @@ "extra_compute_units": 0 }, { - "name": "starknet_simulateTransactions", + "name": "pathfinder_getProof", "block_parsing": { "parser_arg": [ - "0" + "latest" ], - "parser_func": "PARSE_BY_ARG", - "encoding": "base64" + "parser_func": "DEFAULT" }, - "compute_units": 100, + "compute_units": 10, "enabled": true, "category": { "deterministic": true, @@ -797,16 +915,14 @@ "extra_compute_units": 0 }, { - "name": "starknet_traceBlockTransactions", + "name": "pathfinder_getTransactionStatus", "block_parsing": { "parser_arg": [ - "0" + "latest" ], - "parser_func": "PARSE_BY_ARG", - "encoding": "base64" + "parser_func": "DEFAULT" }, - "compute_units": 1000, - "timeout_ms": 20000, + "compute_units": 10, "enabled": true, "category": { "deterministic": true, @@ -821,20 +937,20 @@ { "name": "enabled", "parse_directive": { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"starknet_traceBlockTransactions\",\"params\":[\"latest\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"pathfinder_version\",\"params\":[],\"id\":1}", "function_tag": "VERIFICATION", "result_parsing": { "parser_arg": [ - "0" + "latest" ], - "parser_func": "PARSE_BY_ARG", - "encoding": "base64" + "parser_func": "DEFAULT" }, - "api_name": "starknet_traceBlockTransactions" + "api_name": "pathfinder_version" }, "values": [ { - "expected_value": "*" + "expected_value": "*", + "severity": "Warning" } ] } @@ -891,7 +1007,7 @@ "enabled": true, "collection_data": { "api_interface": "jsonrpc", - "internal_path": "/rpc/v0_7", + "internal_path": "/rpc/v0_6", "type": "POST", "add_on": "" }, @@ -914,7 +1030,7 @@ "enabled": true, "collection_data": { "api_interface": "jsonrpc", - "internal_path": "/rpc/v0_6", + "internal_path": "/ws/rpc/v0_6", "type": "POST", "add_on": "" }, @@ -955,6 +1071,52 @@ ] } ] + }, + { + "enabled": true, + "collection_data": { + "api_interface": "jsonrpc", + "internal_path": "/rpc/v0_7", + "type": "POST", + "add_on": "" + }, + "apis": [], + "headers": [], + "inheritance_apis": [], + "parse_directives": [], + "verifications": [ + { + "name": "chain-id", + "values": [ + { + "expected_value": "0x534e5f5345504f4c4941" + } + ] + } + ] + }, + { + "enabled": true, + "collection_data": { + "api_interface": "jsonrpc", + "internal_path": "/ws/rpc/v0_7", + "type": "POST", + "add_on": "" + }, + "apis": [], + "headers": [], + "inheritance_apis": [], + "parse_directives": [], + "verifications": [ + { + "name": "chain-id", + "values": [ + { + "expected_value": "0x534e5f5345504f4c4941" + } + ] + } + ] } ], "contributor": [ From c74f6434ee389e64879a2ba301cbd6f9e20f78a7 Mon Sep 17 00:00:00 2001 From: Ran Mishael Date: Wed, 18 Dec 2024 16:36:41 +0100 Subject: [PATCH 3/7] lint --- protocol/chainlib/chainproxy/connector.go | 2 +- ...nly.sh => init_avalanch_only_with_node.sh} | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) rename scripts/pre_setups/{init_avalanch_only.sh => init_avalanch_only_with_node.sh} (69%) diff --git a/protocol/chainlib/chainproxy/connector.go b/protocol/chainlib/chainproxy/connector.go index fd6066a268..307f86915a 100644 --- a/protocol/chainlib/chainproxy/connector.go +++ b/protocol/chainlib/chainproxy/connector.go @@ -67,7 +67,7 @@ func NewConnector(ctx context.Context, nConns uint, nodeUrl common.NodeUrl) (*Co rpcClient, err := connector.createConnection(ctx, nodeUrl, connector.numberOfFreeClients()) if err != nil { - return nil, fmt.Errorf("Failed to create the first connection: %w, url: %s", err, nodeUrl.UrlStr()) + return nil, fmt.Errorf("failed to create the first connection: %w, url: %s", err, nodeUrl.UrlStr()) } connector.addClient(rpcClient) diff --git a/scripts/pre_setups/init_avalanch_only.sh b/scripts/pre_setups/init_avalanch_only_with_node.sh similarity index 69% rename from scripts/pre_setups/init_avalanch_only.sh rename to scripts/pre_setups/init_avalanch_only_with_node.sh index 03bdf3fd4a..42a8242656 100755 --- a/scripts/pre_setups/init_avalanch_only.sh +++ b/scripts/pre_setups/init_avalanch_only_with_node.sh @@ -9,12 +9,29 @@ rm $LOGS_DIR/*.log killall screen screen -wipe + +echo "[Test Setup] installing all binaries" +make install-all + +echo "[Test Setup] setting up a new lava node" +screen -d -m -S node bash -c "./scripts/start_env_dev.sh" +screen -ls +echo "[Test Setup] waiting lava node to start" +sleep 3 +wait_for_lava_node_to_start + GASPRICE="0.00002ulava" specs=$(get_all_specs) lavad tx gov submit-legacy-proposal spec-add $specs --lava-dev-test -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE & +wait_next_block +wait_next_block lavad tx gov vote 1 yes -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE +sleep 4 -lavad tx gov submit-legacy-proposal plans-add ./cookbook/plans/test_plans/default.json -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE +# Plans proposal +lavad tx gov submit-legacy-proposal plans-add ./cookbook/plans/test_plans/default.json,./cookbook/plans/test_plans/temporary-add.json -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE +wait_next_block +wait_next_block lavad tx gov vote 2 yes -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE sleep 4 @@ -25,13 +42,14 @@ PROVIDERSTAKE="500000000000ulava" PROVIDER1_LISTENER="127.0.0.1:2221" lavad tx subscription buy DefaultPlan $(lavad keys show user1 -a) -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE - +wait_next_block lavad tx pairing stake-provider "AVAX" $PROVIDERSTAKE "$PROVIDER1_LISTENER,1" 1 $(operator_address) -y --from servicer1 --provider-moniker "dummyMoniker" --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE +lavad tx project set-policy $(lavad keys show user1 -a)-admin ./cookbook/projects/policy_all_chains_with_addon.yml -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE sleep_until_next_epoch screen -d -m -S provider1 bash -c "source ~/.bashrc; lavap rpcprovider \ -$PROVIDER1_LISTENER AVAX jsonrpc $AVALANCH_PJRPC \ +./config/provider_examples/avalanch_internal_paths_example.yml \ $EXTRA_PROVIDER_FLAGS --geolocation 1 --log_level debug --from servicer1 2>&1 | tee $LOGS_DIR/PROVIDER1.log" && sleep 0.25 screen -d -m -S consumers bash -c "source ~/.bashrc; lavap rpcconsumer \ From fa26249edec732c633f9e2b3296d0800352e1971 Mon Sep 17 00:00:00 2001 From: Ran Mishael Date: Wed, 18 Dec 2024 16:38:35 +0100 Subject: [PATCH 4/7] fix test --- protocol/chainlib/chain_router_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/protocol/chainlib/chain_router_test.go b/protocol/chainlib/chain_router_test.go index 7d80f343a1..db1b9fa8d6 100644 --- a/protocol/chainlib/chain_router_test.go +++ b/protocol/chainlib/chain_router_test.go @@ -2,7 +2,6 @@ package chainlib import ( "context" - "fmt" "log" "net" "os" @@ -2205,9 +2204,6 @@ func TestChainRouterWithInternalPaths(t *testing.T) { actualNodeUrlsCount += len(actualEndpoint.NodeUrls) expectedNodeUrls := play.expectedServicesToNodeUrls[routerKey] - require.Len(t, actualEndpoint.NodeUrls, len(expectedNodeUrls), - fmt.Sprintf("RouterKey: %v, NodeUrls: %v", routerKey, actualEndpoint.NodeUrls)) - for _, actualNodeUrl := range actualEndpoint.NodeUrls { found := false for _, expectedNodeUrls := range expectedNodeUrls { From 0743d795f46b1e12c764deaee4b6a9eded7f8253 Mon Sep 17 00:00:00 2001 From: Ran Mishael Date: Wed, 18 Dec 2024 17:00:08 +0100 Subject: [PATCH 5/7] fix statistical consensus query test failures. --- testutil/network/network.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/testutil/network/network.go b/testutil/network/network.go index a1b72c2e92..0f2f160152 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -2,6 +2,7 @@ package network import ( "fmt" + "net" "testing" "time" @@ -47,11 +48,38 @@ func New(t *testing.T, configs ...network.Config) *network.Network { return net } +// findFreePort returns an available port number +func findFreePort() (int, error) { + addr, err := net.ResolveTCPAddr("tcp", "localhost:0") + if err != nil { + return 0, err + } + + l, err := net.ListenTCP("tcp", addr) + if err != nil { + return 0, err + } + defer l.Close() + + return l.Addr().(*net.TCPAddr).Port, nil +} + // DefaultConfig will initialize config for the network with custom application, // genesis and single validator. All other parameters are inherited from cosmos-sdk/testutil/network.DefaultConfig func DefaultConfig() network.Config { encoding := app.MakeEncodingConfig() chainID := "chain-" + tmrand.NewRand().Str(6) + + // Find available ports for API and gRPC + apiPort, err := findFreePort() + if err != nil { + panic(err) + } + grpcPort, err := findFreePort() + if err != nil { + panic(err) + } + return network.Config{ Codec: encoding.Marshaler, TxConfig: encoding.TxConfig, @@ -81,5 +109,7 @@ func DefaultConfig() network.Config { CleanupDir: true, SigningAlgo: string(hd.Secp256k1Type), KeyringOptions: []keyring.Option{}, + APIAddress: fmt.Sprintf("tcp://0.0.0.0:%d", apiPort), + GRPCAddress: fmt.Sprintf("0.0.0.0:%d", grpcPort), } } From 94712fc6f8707ac0774190b9fcdacef1556037b7 Mon Sep 17 00:00:00 2001 From: Ran Mishael Date: Wed, 18 Dec 2024 17:04:30 +0100 Subject: [PATCH 6/7] lintush --- testutil/network/network.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/testutil/network/network.go b/testutil/network/network.go index 0f2f160152..3cdaa939e7 100644 --- a/testutil/network/network.go +++ b/testutil/network/network.go @@ -61,7 +61,11 @@ func findFreePort() (int, error) { } defer l.Close() - return l.Addr().(*net.TCPAddr).Port, nil + addr, ok := l.Addr().(*net.TCPAddr) + if !ok { + return 0, fmt.Errorf("failed to get TCP address") + } + return addr.Port, nil } // DefaultConfig will initialize config for the network with custom application, From ebfaa9a7405f3698d189dc2e09d5041830d6c86a Mon Sep 17 00:00:00 2001 From: Ran Mishael Date: Thu, 19 Dec 2024 12:33:08 +0100 Subject: [PATCH 7/7] fix PR comments --- protocol/chainlib/chain_router.go | 2 -- protocol/chainlib/jsonRPC.go | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/protocol/chainlib/chain_router.go b/protocol/chainlib/chain_router.go index bbef0ccb6e..eab820d81e 100644 --- a/protocol/chainlib/chain_router.go +++ b/protocol/chainlib/chain_router.go @@ -188,8 +188,6 @@ func (cri *chainRouterImpl) BatchNodeUrlsByServices(rpcProviderEndpoint lavasess nodeUrl.Addons = append(nodeUrl.Addons, WebSocketExtension) routerKey.SetExtensions(nodeUrl.Addons) } - - // _, isAlreadyAutoGenerated := autoGeneratedInternalPaths[nodeUrl.InternalPath] cri.setRouterKeyInBatch(nodeUrl, returnedBatch, routerKey, rpcProviderEndpoint, true) // will override existing entries if nodeUrl.InternalPath == "" { // root path diff --git a/protocol/chainlib/jsonRPC.go b/protocol/chainlib/jsonRPC.go index 8e9ab86c7f..f19dc71d95 100644 --- a/protocol/chainlib/jsonRPC.go +++ b/protocol/chainlib/jsonRPC.go @@ -567,6 +567,7 @@ func (cp *JrpcChainProxy) start(ctx context.Context, nConns uint, nodeUrl common isWs, parseErr := IsUrlWebSocket(nodeUrl.Url) if parseErr == nil && isWs { newUrl := strings.TrimSuffix(nodeUrl.Url, "/") + "/ws" + originalUrl := nodeUrl.Url utils.LavaFormatWarning("Failed creating connector for ws, trying to create with /ws path", err, utils.LogAttr("url", nodeUrl.UrlStr()), utils.LogAttr("newUrl", newUrl)) nodeUrl.Url = newUrl conn, newConnErr := chainproxy.NewConnector(ctx, nConns, nodeUrl) @@ -574,6 +575,7 @@ func (cp *JrpcChainProxy) start(ctx context.Context, nConns uint, nodeUrl common cp.conn = conn return nil } + nodeUrl.Url = originalUrl } return err }