Skip to content

Commit

Permalink
Merge branch 'main' into PRT-add-consumer-add-to-qos-report
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet authored Dec 3, 2024
2 parents 0593bb2 + 064945d commit a87ceb8
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ endpoints:
- api-interface: tendermintrpc
chain-id: LAV1
network-address:
address: "127.0.0.1:2220"
address: "127.0.0.1:2224"
node-urls:
- url: ws://127.0.0.1:26657/websocket
- url: http://127.0.0.1:26657
- url: http://127.0.0.1:26657
addons:
- archive
- url: https://trustless-api.com
- url: http://127.0.0.1:4444
methods:
- block
- block_by_hash
Expand All @@ -18,7 +18,7 @@ endpoints:
- api-interface: grpc
chain-id: LAV1
network-address:
address: "127.0.0.1:2220"
address: "127.0.0.1:2224"
node-urls:
- url: 127.0.0.1:9090
- url: 127.0.0.1:9090
Expand All @@ -27,7 +27,7 @@ endpoints:
- api-interface: rest
chain-id: LAV1
network-address:
address: "127.0.0.1:2220"
address: "127.0.0.1:2224"
node-urls:
- url: http://127.0.0.1:1317
- url: http://127.0.0.1:1317
Expand Down
20 changes: 20 additions & 0 deletions cookbook/projects/policy_all_chains_with_extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ Policy:
extensions:
- "archive"
mixed: true
- chain_id: OSMOSIS
requirements:
- collection:
api_interface: "rest"
type: "GET"
extensions:
- "archive"
mixed: true
- collection:
api_interface: "grpc"
type: ""
extensions:
- "archive"
mixed: true
- collection:
api_interface: "tendermintrpc"
type: ""
extensions:
- "archive"
mixed: true
- chain_id: COSMOSHUB
requirements:
- collection:
Expand Down
151 changes: 90 additions & 61 deletions cookbook/specs/solana.json
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,91 @@
"stateful": 0
},
"extra_compute_units": 0
}
],
"headers": [],
"inheritance_apis": [],
"parse_directives": [
{
"function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"getLatestBlockhash\",\"params\":[{\"commitment\":\"finalized\"}],\"id\":1}",
"function_tag": "GET_BLOCKNUM",
"result_parsing": {
"parser_arg": [
"0",
"context",
"slot"
],
"parser_func": "PARSE_CANONICAL"
},
"api_name": "getLatestBlockhash"
},
{
"function_tag": "GET_BLOCK_BY_NUM",
"function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"getBlock\",\"params\":[%d,{\"transactionDetails\":\"none\",\"rewards\":false}],\"id\":1}",
"result_parsing": {
"parser_arg": [
"0",
"blockhash"
],
"parser_func": "PARSE_CANONICAL",
"encoding": "base64"
},
"api_name": "getBlock"
}
],
"verifications": [
{
"name": "version",
"parse_directive": {
"function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"getVersion\",\"params\":[],\"id\":1}",
"function_tag": "VERIFICATION",
"result_parsing": {
"parser_arg": [
"0",
"solana-core"
],
"parser_func": "PARSE_CANONICAL"
},
"api_name": "getVersion"
},
"values": [
{
"expected_value": "*"
}
]
},
{
"name": "tokens-owner-indexed",
"parse_directive": {
"function_template": "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"getTokenAccountsByOwner\",\"params\":[\"4Qkev8aNZcqFNSRhQzwyLMFSsi94jHqE8WNVTJzTP99F\",{\"programId\":\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\"},{\"encoding\":\"jsonParsed\"}]}",
"function_tag": "VERIFICATION",
"result_parsing": {
"parser_arg": [
"0",
"value"
],
"parser_func": "PARSE_CANONICAL"
},
"api_name": "getTokenAccountsByOwner"
},
"values": [
{
"expected_value": "*",
"severity": "Warning"
}
]
}
]
},
{
"enabled": true,
"collection_data": {
"api_interface": "jsonrpc",
"internal_path": "/ws",
"type": "POST",
"add_on": ""
},
"apis": [
{
"name": "accountSubscribe",
"block_parsing": {
Expand Down Expand Up @@ -1294,30 +1378,17 @@
"inheritance_apis": [],
"parse_directives": [
{
"function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"getLatestBlockhash\",\"params\":[{\"commitment\":\"finalized\"}],\"id\":1}",
"function_tag": "GET_BLOCKNUM",
"result_parsing": {
"parser_arg": [
"0",
"context",
"slot"
],
"parser_func": "PARSE_CANONICAL"
},
"api_name": "getLatestBlockhash"
"parser_func": "DEFAULT"
}
},
{
"function_template": "%d",
"function_tag": "GET_BLOCK_BY_NUM",
"function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"getBlock\",\"params\":[%d,{\"transactionDetails\":\"none\",\"rewards\":false}],\"id\":1}",
"result_parsing": {
"parser_arg": [
"0",
"blockhash"
],
"parser_func": "PARSE_CANONICAL",
"encoding": "base64"
},
"api_name": "getBlock"
"parser_func": "DEFAULT"
}
},
{
"function_tag": "SUBSCRIBE",
Expand Down Expand Up @@ -1401,49 +1472,7 @@
"api_name": "voteUnsubscribe"
}
],
"verifications": [
{
"name": "version",
"parse_directive": {
"function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"getVersion\",\"params\":[],\"id\":1}",
"function_tag": "VERIFICATION",
"result_parsing": {
"parser_arg": [
"0",
"solana-core"
],
"parser_func": "PARSE_CANONICAL"
},
"api_name": "getVersion"
},
"values": [
{
"expected_value": "*"
}
]
},
{
"name": "tokens-owner-indexed",
"parse_directive": {
"function_template": "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"getTokenAccountsByOwner\",\"params\":[\"4Qkev8aNZcqFNSRhQzwyLMFSsi94jHqE8WNVTJzTP99F\",{\"programId\":\"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA\"},{\"encoding\":\"jsonParsed\"}]}",
"function_tag": "VERIFICATION",
"result_parsing": {
"parser_arg": [
"0",
"value"
],
"parser_func": "PARSE_CANONICAL"
},
"api_name": "getTokenAccountsByOwner"
},
"values": [
{
"expected_value": "*",
"severity": "Warning"
}
]
}
]
"verifications": []
}
]
},
Expand Down
24 changes: 21 additions & 3 deletions protocol/chainlib/chainproxy/rpcclient/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,16 @@ func (h *handler) handleImmediate(msg *JsonrpcMessage) bool {
h.handleSubscriptionResultTendermint(msg)
return true
case msg.isEthereumNotification():
if strings.HasSuffix(msg.Method, notificationMethodSuffix) {
if strings.HasSuffix(msg.Method, ethereumNotificationMethodSuffix) {
h.handleSubscriptionResultEthereum(msg)
return true
} else if strings.HasSuffix(msg.Method, solanaNotificationMethodSuffix) {
h.handleSubscriptionResultSolana(msg)
return true
}
return false
case msg.isStarkNetPathfinderNotification():
if strings.HasSuffix(msg.Method, notificationMethodSuffix) {
if strings.HasSuffix(msg.Method, ethereumNotificationMethodSuffix) {
h.handleSubscriptionResultStarkNetPathfinder(msg)
return true
}
Expand All @@ -258,7 +261,7 @@ func (h *handler) handleImmediate(msg *JsonrpcMessage) bool {
}

func (h *handler) handleSubscriptionResultStarkNetPathfinder(msg *JsonrpcMessage) {
var result starkNetPathfinderSubscriptionResult
var result integerIdSubscriptionResult
if err := json.Unmarshal(msg.Result, &result); err != nil {
utils.LavaFormatTrace("Dropping invalid starknet pathfinder subscription message",
utils.LogAttr("err", err),
Expand Down Expand Up @@ -290,6 +293,21 @@ func (h *handler) handleSubscriptionResultEthereum(msg *JsonrpcMessage) {
}
}

func (h *handler) handleSubscriptionResultSolana(msg *JsonrpcMessage) {
var result integerIdSubscriptionResult
if err := json.Unmarshal(msg.Params, &result); err != nil {
utils.LavaFormatTrace("Dropping invalid solana subscription message",
utils.LogAttr("err", err),
utils.LogAttr("params", string(msg.Params)),
)
h.log.Debug("Dropping invalid subscription message")
return
}
if h.clientSubs[strconv.Itoa(result.ID)] != nil {
h.clientSubs[strconv.Itoa(result.ID)].deliver(msg)
}
}

func (h *handler) handleSubscriptionResultTendermint(msg *JsonrpcMessage) {
var result tendermintSubscriptionResult
if err := json.Unmarshal(msg.Result, &result); err != nil {
Expand Down
13 changes: 7 additions & 6 deletions protocol/chainlib/chainproxy/rpcclient/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ import (
)

const (
Vsn = "2.0"
serviceMethodSeparator = "_"
subscribeMethodSuffix = "_subscribe"
unsubscribeMethodSuffix = "_unsubscribe"
notificationMethodSuffix = "_subscription"
Vsn = "2.0"
serviceMethodSeparator = "_"
subscribeMethodSuffix = "_subscribe"
unsubscribeMethodSuffix = "_unsubscribe"
ethereumNotificationMethodSuffix = "_subscription"
solanaNotificationMethodSuffix = "Notification"

defaultWriteTimeout = 10 * time.Second // used if context has no deadline
)
Expand All @@ -49,7 +50,7 @@ type ethereumSubscriptionResult struct {
Result json.RawMessage `json:"result,omitempty"`
}

type starkNetPathfinderSubscriptionResult struct {
type integerIdSubscriptionResult struct {
ID int `json:"subscription"`
Result json.RawMessage `json:"result,omitempty"`
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/chainlib/chainproxy/rpcclient/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (n *Notifier) send(sub *Subscription, data json.RawMessage) error {
ctx := context.Background()
return n.h.conn.writeJSON(ctx, &JsonrpcMessage{
Version: Vsn,
Method: n.namespace + notificationMethodSuffix,
Method: n.namespace + ethereumNotificationMethodSuffix,
Params: params,
})
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/integration/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2154,7 +2154,7 @@ func TestArchiveProvidersRetryOnParsedHash(t *testing.T) {
ChainId: specId,
SeenBlock: 1005,
BlocksHashesToHeights: []*pairingtypes.BlockHashToHeight{{Hash: blockHash, Height: spectypes.NOT_APPLICABLE}},
}) // caching in the portal doesn't care about hashes, and we don't have data on finalization yet
}) // caching in the consumer doesn't care about hashes, and we don't have data on finalization yet
cancel()
if err != nil {
continue
Expand Down
2 changes: 1 addition & 1 deletion protocol/rpcconsumer/rpcconsumer_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func (rpccs *RPCConsumerServer) sendRelayToProvider(
SharedStateId: sharedStateId,
SeenBlock: protocolMessage.RelayPrivateData().SeenBlock,
BlocksHashesToHeights: rpccs.newBlocksHashesToHeightsSliceFromRequestedBlockHashes(protocolMessage.GetRequestedBlocksHashes()),
}) // caching in the portal doesn't care about hashes, and we don't have data on finalization yet
}) // caching in the consumer doesn't care about hashes, and we don't have data on finalization yet
cancel()
reply := cacheReply.GetReply()

Expand Down
6 changes: 5 additions & 1 deletion scripts/init_chain_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ PROVIDERSTAKE="500000000000ulava"
PROVIDER1_LISTENER="127.0.0.1:2221"
PROVIDER2_LISTENER="127.0.0.1:2222"
PROVIDER3_LISTENER="127.0.0.1:2223"
# PROVIDER4_LISTENER="127.0.0.1:2224"

sleep 4

Expand All @@ -67,7 +68,7 @@ lavad tx gov vote $(latest_vote) yes -y --from alice --gas-adjustment "1.5" --ga
echo; echo "#### Buy DefaultPlan subscription for user1 ####"
lavad tx subscription buy DefaultPlan $(lavad keys show user1 -a) --enable-auto-renewal -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE
# wait_count_blocks 2
# 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
# lavad tx project set-policy $(lavad keys show user1 -a)-admin ./cookbook/projects/policy_all_chains_with_extension.yml -y --from user1 --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE

# MANTLE
CHAINS="ETH1,SEP1,HOL1,OSMOSIS,FTM250,CELO,LAV1,OSMOSIST,ALFAJORES,ARB1,ARBN,APT1,STRK,JUN1,COSMOSHUB,POLYGON1,EVMOS,OPTM,BASES,CANTO,SUIT,SOLANA,BSC,AXELAR,AVAX,FVM,NEAR,SQDSUBGRAPH,AGR,AGRT,KOIIT,AVAXT,CELESTIATM"
Expand All @@ -82,6 +83,9 @@ lavad tx pairing bulk-stake-provider $BASE_CHAINS $PROVIDERSTAKE "$PROVIDER2_LIS
echo; echo "#### Staking provider 3 ####"
lavad tx pairing bulk-stake-provider $BASE_CHAINS $PROVIDERSTAKE "$PROVIDER3_LISTENER,1" 1 $(operator_address) -y --delegate-commission 50 --from servicer3 --provider-moniker "servicer3" --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE

# echo; echo "#### Staking provider 4 ####"
# lavad tx pairing bulk-stake-provider $BASE_CHAINS $PROVIDERSTAKE "$PROVIDER4_LISTENER,1" 1 $(operator_address) -y --delegate-commission 50 --from servicer4 --provider-moniker "servicer4" --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE

echo; echo "#### Waiting 1 block ####"
wait_count_blocks 1

Expand Down
2 changes: 1 addition & 1 deletion scripts/pre_setups/init_eth_archive_mix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ screen -d -m -S provider$i bash -c "source ~/.bashrc; lavap rpcprovider \
$EXTRA_PROVIDER_FLAGS --geolocation 1 --log_level debug --from servicer$i --chain-id lava 2>&1 | tee $LOGS_DIR/PROVIDER$i.log" && sleep 0.25

screen -d -m -S portals bash -c "source ~/.bashrc; lavap rpcconsumer consumer_examples/ethereum_example.yml\
$EXTRA_PORTAL_FLAGS --cache-be "127.0.0.1:7778" --geolocation 1 --debug-relays --log_level debug --from user1 --chain-id lava --allow-insecure-provider-dialing 2>&1 | tee $LOGS_DIR/PORTAL.log" && sleep 0.25
$EXTRA_PORTAL_FLAGS --cache-be "127.0.0.1:7778" --geolocation 1 --debug-relays --log_level debug --from user1 --chain-id lava --allow-insecure-provider-dialing 2>&1 | tee $LOGS_DIR/CONSUMER.log" && sleep 0.25
echo "--- setting up screens done ---"
screen -ls

Expand Down
4 changes: 2 additions & 2 deletions scripts/setup_providers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ $EXTRA_PROVIDER_FLAGS --geolocation "$GEOLOCATION" --log_level debug --from serv
# $PROVIDER3_LISTENER MANTLE jsonrpc '$MANTLE_JRPC' \

echo; echo "#### Starting consumer ####"
# Setup Portal
# Setup Consumer
screen -d -m -S portals bash -c "source ~/.bashrc; lavap rpcconsumer consumer_examples/full_consumer_example.yml\
$EXTRA_PORTAL_FLAGS --cache-be "127.0.0.1:7778" --geolocation "$GEOLOCATION" --debug-relays --log_level debug --from user1 --chain-id lava --allow-insecure-provider-dialing --strategy distributed 2>&1 | tee $LOGS_DIR/PORTAL.log" && sleep 0.25
$EXTRA_PORTAL_FLAGS --cache-be "127.0.0.1:7778" --geolocation "$GEOLOCATION" --debug-relays --log_level debug --from user1 --chain-id lava --allow-insecure-provider-dialing --strategy distributed 2>&1 | tee $LOGS_DIR/CONSUMER.log" && sleep 0.25
# 127.0.0.1:3385 MANTLE jsonrpc \

echo "--- setting up screens done ---"
Expand Down
Loading

0 comments on commit a87ceb8

Please sign in to comment.