From 67ae680b0ddac1ed47362cfeb006b3ba8b07707f Mon Sep 17 00:00:00 2001 From: Oren Date: Thu, 28 Nov 2024 11:29:17 +0200 Subject: [PATCH 1/4] add subscription APIs to solana spec --- cookbook/specs/solana.json | 405 +++++++++++++++++++++++++++++++++++++ 1 file changed, 405 insertions(+) mode change 100644 => 100755 cookbook/specs/solana.json diff --git a/cookbook/specs/solana.json b/cookbook/specs/solana.json old mode 100644 new mode 100755 index e6b596641d..ac58a3a5b3 --- a/cookbook/specs/solana.json +++ b/cookbook/specs/solana.json @@ -964,6 +964,330 @@ "stateful": 0 }, "extra_compute_units": 0 + }, + { + "name": "accountSubscribe", + "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": "accountUnsubscribe", + "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": "blockSubscribe", + "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": "blockUnsubscribe", + "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": "logsSubscribe", + "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": "logsUnsubscribe", + "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": "programSubscribe", + "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": "programUnsubscribe", + "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": "rootSubscribe", + "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": "rootUnsubscribe", + "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": "signatureSubscribe", + "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": "signatureUnsubscribe", + "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": "slotSubscribe", + "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": "slotUnsubscribe", + "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": "slotsUpdatesSubscribe", + "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": "slotsUpdatesUnsubscribe", + "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": "voteSubscribe", + "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": "voteUnsubscribe", + "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 } ], "headers": [], @@ -994,6 +1318,87 @@ "encoding": "base64" }, "api_name": "getBlock" + }, + { + "function_tag": "SUBSCRIBE", + "api_name": "accountSubscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"accountUnsubscribe\",\"params\":[0],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "accountUnsubscribe" + }, + { + "function_tag": "SUBSCRIBE", + "api_name": "blockSubscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"blockUnsubscribe\",\"params\":[0],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "blockUnsubscribe" + }, + { + "function_tag": "SUBSCRIBE", + "api_name": "logsSubscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"logsUnsubscribe\",\"params\":[0],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "logsUnsubscribe" + }, + { + "function_tag": "SUBSCRIBE", + "api_name": "programSubscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"programUnsubscribe\",\"params\":[0],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "programUnsubscribe" + }, + { + "function_tag": "SUBSCRIBE", + "api_name": "rootSubscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"rootUnsubscribe\",\"params\":[0],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "rootUnsubscribe" + }, + { + "function_tag": "SUBSCRIBE", + "api_name": "signatureSubscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"signatureUnsubscribe\",\"params\":[0],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "signatureUnsubscribe" + }, + { + "function_tag": "SUBSCRIBE", + "api_name": "slotSubscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotUnsubscribe\",\"params\":[0],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "slotUnsubscribe" + }, + { + "function_tag": "SUBSCRIBE", + "api_name": "slotsUpdatesSubscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotsUpdatesUnsubscribe\",\"params\":[0],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "slotsUpdatesUnsubscribe" + }, + { + "function_tag": "SUBSCRIBE", + "api_name": "voteSubscribe" + }, + { + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"voteUnsubscribe\",\"params\":[0],\"id\":1}", + "function_tag": "UNSUBSCRIBE", + "api_name": "voteUnsubscribe" } ], "verifications": [ From 5bcbd42aa5c220a3e8dbc219355acc8b1a5093ad Mon Sep 17 00:00:00 2001 From: Oren Date: Thu, 28 Nov 2024 15:53:29 +0200 Subject: [PATCH 2/4] minor fix for multiple SUBSCRIBE tags --- protocol/chainlib/base_chain_parser.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/protocol/chainlib/base_chain_parser.go b/protocol/chainlib/base_chain_parser.go index fa730cde48..6cc5e8ea24 100644 --- a/protocol/chainlib/base_chain_parser.go +++ b/protocol/chainlib/base_chain_parser.go @@ -429,9 +429,21 @@ func getServiceApis( } for _, parsing := range apiCollection.ParseDirectives { - taggedApis[parsing.FunctionTag] = TaggedContainer{ - Parsing: parsing, - ApiCollection: apiCollection, + // We do this because some specs may have multiple parse directives + // with the same tag - SUBSCRIBE (like in Solana). + // + // Since the function tag is not used for handling the subscription flow, + // we can ignore the extra parse directives and take only the first one. The + // subscription flow is handled by the consumer websocket manager and the chain router + // that uses the api collection to fetch the correct parse directive. + // + // The only place the SUBSCRIBE tag is checked against the taggedApis map is in the chain parser with GetParsingByTag. + // But there, we're not interested in the parse directive, only if the tag is present. + if _, ok := taggedApis[parsing.FunctionTag]; !ok { + taggedApis[parsing.FunctionTag] = TaggedContainer{ + Parsing: parsing, + ApiCollection: apiCollection, + } } } From 8d6f4264b74f74bbe980cfb73ef576291a2916d8 Mon Sep 17 00:00:00 2001 From: Oren Date: Sun, 1 Dec 2024 10:23:53 +0200 Subject: [PATCH 3/4] fix unsubscribe methods --- cookbook/specs/solana.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cookbook/specs/solana.json b/cookbook/specs/solana.json index ac58a3a5b3..9a0b9d39e1 100755 --- a/cookbook/specs/solana.json +++ b/cookbook/specs/solana.json @@ -1324,7 +1324,7 @@ "api_name": "accountSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"accountUnsubscribe\",\"params\":[0],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"accountUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "accountUnsubscribe" }, @@ -1333,7 +1333,7 @@ "api_name": "blockSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"blockUnsubscribe\",\"params\":[0],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"blockUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "blockUnsubscribe" }, @@ -1342,7 +1342,7 @@ "api_name": "logsSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"logsUnsubscribe\",\"params\":[0],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"logsUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "logsUnsubscribe" }, @@ -1351,7 +1351,7 @@ "api_name": "programSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"programUnsubscribe\",\"params\":[0],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"programUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "programUnsubscribe" }, @@ -1360,7 +1360,7 @@ "api_name": "rootSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"rootUnsubscribe\",\"params\":[0],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"rootUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "rootUnsubscribe" }, @@ -1369,7 +1369,7 @@ "api_name": "signatureSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"signatureUnsubscribe\",\"params\":[0],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"signatureUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "signatureUnsubscribe" }, @@ -1378,7 +1378,7 @@ "api_name": "slotSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotUnsubscribe\",\"params\":[0],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "slotUnsubscribe" }, @@ -1387,7 +1387,7 @@ "api_name": "slotsUpdatesSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotsUpdatesUnsubscribe\",\"params\":[0],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotsUpdatesUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "slotsUpdatesUnsubscribe" }, @@ -1396,7 +1396,7 @@ "api_name": "voteSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"voteUnsubscribe\",\"params\":[0],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"voteUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "voteUnsubscribe" } From b30d822b3a4eee1800246a0bd41272274215d600 Mon Sep 17 00:00:00 2001 From: Oren Date: Sun, 1 Dec 2024 11:25:16 +0200 Subject: [PATCH 4/4] change solana unsubscribe params from %s to %d --- cookbook/specs/solana.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cookbook/specs/solana.json b/cookbook/specs/solana.json index 9a0b9d39e1..5089de1331 100755 --- a/cookbook/specs/solana.json +++ b/cookbook/specs/solana.json @@ -1324,7 +1324,7 @@ "api_name": "accountSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"accountUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"accountUnsubscribe\",\"params\":[%d],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "accountUnsubscribe" }, @@ -1333,7 +1333,7 @@ "api_name": "blockSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"blockUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"blockUnsubscribe\",\"params\":[%d],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "blockUnsubscribe" }, @@ -1342,7 +1342,7 @@ "api_name": "logsSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"logsUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"logsUnsubscribe\",\"params\":[%d],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "logsUnsubscribe" }, @@ -1351,7 +1351,7 @@ "api_name": "programSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"programUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"programUnsubscribe\",\"params\":[%d],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "programUnsubscribe" }, @@ -1360,7 +1360,7 @@ "api_name": "rootSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"rootUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"rootUnsubscribe\",\"params\":[%d],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "rootUnsubscribe" }, @@ -1369,7 +1369,7 @@ "api_name": "signatureSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"signatureUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"signatureUnsubscribe\",\"params\":[%d],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "signatureUnsubscribe" }, @@ -1378,7 +1378,7 @@ "api_name": "slotSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotUnsubscribe\",\"params\":[%d],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "slotUnsubscribe" }, @@ -1387,7 +1387,7 @@ "api_name": "slotsUpdatesSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotsUpdatesUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"slotsUpdatesUnsubscribe\",\"params\":[%d],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "slotsUpdatesUnsubscribe" }, @@ -1396,7 +1396,7 @@ "api_name": "voteSubscribe" }, { - "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"voteUnsubscribe\",\"params\":[\"%s\"],\"id\":1}", + "function_template": "{\"jsonrpc\":\"2.0\",\"method\":\"voteUnsubscribe\",\"params\":[%d],\"id\":1}", "function_tag": "UNSUBSCRIBE", "api_name": "voteUnsubscribe" }