-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
225 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"gopkg.in/yaml.v3" | ||
"os" | ||
) | ||
|
||
type Backend struct { | ||
Rpc string | ||
|
||
// examples: | ||
// [1, 100] => from block 1 to block 100 (subnode) | ||
// [10] => last 10 recent blocks | ||
// [] => archive node | ||
Blocks []int | ||
} | ||
|
||
type Config struct { | ||
Upstream []Backend `yaml:",flow"` | ||
} | ||
|
||
type BackendNodeType uint8 | ||
|
||
const ( | ||
BackendNodeTypePruned BackendNodeType = 0 | ||
BackendNodeTypeSubNode BackendNodeType = 1 | ||
BackendNodeTypeArchive BackendNodeType = 2 | ||
) | ||
|
||
func GetBackendNodeType(b *Backend) BackendNodeType { | ||
switch c := len(b.Blocks); c { | ||
case 0: | ||
return BackendNodeTypeArchive | ||
case 1: | ||
return BackendNodeTypePruned | ||
case 2: | ||
return BackendNodeTypeSubNode | ||
default: | ||
panic("invalid blocks config") | ||
} | ||
} | ||
|
||
func SelectPrunedNode(cfg *Config) *Backend { | ||
for _, s := range cfg.Upstream { | ||
if GetBackendNodeType(&s) == BackendNodeTypePruned { | ||
return &s | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func LoadConfigFromFile(filename string) (*Config, error) { | ||
buf, err := os.ReadFile(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
c, err := LoadConfigFromBytes(buf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return c, err | ||
} | ||
|
||
func LoadConfigFromBytes(buf []byte) (*Config, error) { | ||
c := &Config{} | ||
err := yaml.Unmarshal(buf, c) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return c, err | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestLoadConfigFromBytes(t *testing.T) { | ||
var data = ` | ||
upstream: | ||
- rpc: "http://pruned" | ||
blocks: [50] | ||
- rpc: "http://subnode" | ||
blocks: [100, 200] | ||
- rpc: "http://archive" | ||
blocks: [] | ||
` | ||
cfg, err := LoadConfigFromBytes([]byte(data)) | ||
assert.NoError(t, err) | ||
fmt.Printf("%+v\n", cfg) | ||
} | ||
|
||
func TestGetBackendNodeType(t *testing.T) { | ||
b := Backend{ | ||
Rpc: "http://pruned", | ||
Blocks: []int{10}, | ||
} | ||
|
||
assert.Equal(t, GetBackendNodeType(&b), BackendNodeTypePruned) | ||
} | ||
|
||
func TestSelectPrunedNode(t *testing.T) { | ||
pruned := Backend{ | ||
Rpc: "http://pruned", | ||
Blocks: []int{10}, | ||
} | ||
archive := Backend{ | ||
Rpc: "http://archive", | ||
Blocks: []int{}, | ||
} | ||
|
||
cfg := Config{ | ||
Upstream: []Backend{pruned, archive}, | ||
} | ||
|
||
assert.Equal(t, SelectPrunedNode(&cfg).Rpc, pruned.Rpc) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
### Tendermint RPC | ||
|
||
#### URI over HTTP | ||
|
||
https://docs.tendermint.com/v0.34/rpc/#/ | ||
|
||
|
||
[ ] /abci_info? | ||
route to pruned node | ||
[ ] /abci_query?path=_&data=_&height=_&prove=_ | ||
base on height | ||
[ ] /block?height=_ | ||
base on height | ||
[ ] /block_by_hash?hash=_ | ||
not supported, should use indexer instead | ||
[ ] /block_results?height=_ | ||
base on height | ||
[ ] /block_search?query=_&page=_&per_page=_&order_by=_ | ||
not supported, should be used with indexer | ||
[ ] /blockchain?minHeight=_&maxHeight=_ | ||
base on minHeight & maxHeight | ||
[ ] /broadcast_evidence?evidence=_ | ||
route to pruned node | ||
[ ] /broadcast_tx_async?tx=_ | ||
route to pruned node | ||
[ ] /broadcast_tx_commit?tx=_ | ||
route to pruned node | ||
[ ] /broadcast_tx_sync?tx=_ | ||
route to pruned node | ||
[ ] /check_tx?tx=_ | ||
route to pruned node | ||
[ ] /commit?height=_ | ||
base on height | ||
[ ] /consensus_params?height=_ | ||
base on height | ||
[ ] /consensus_state? | ||
route to pruned node | ||
[ ] /dump_consensus_state? | ||
route to pruned node | ||
[ ] /genesis? | ||
route to pruned node | ||
[ ] /genesis_chunked?chunk=_ | ||
route to pruned node | ||
[ ] /health? | ||
route to pruned node | ||
[ ] /net_info? | ||
route to pruned node | ||
[ ] /num_unconfirmed_txs? | ||
route to pruned node | ||
[ ] /status? | ||
route to pruned node | ||
[ ] /subscribe?query=_ | ||
not supported, use pruned node directly | ||
[ ] /tx?hash=_&prove=_ | ||
not supported, should use indexer instead | ||
[ ] /tx_search?query=_&prove=_&page=_&per_page=_&order_by=_ | ||
not supported, should use indexer instead | ||
[ ] /unconfirmed_txs?limit=_ | ||
route to pruned node | ||
[ ] /unsubscribe?query=_ | ||
not supported, use pruned node directly | ||
[ ] /unsubscribe_all? | ||
not supported, use pruned node directly | ||
[ ] /validators?height=_&page=_&per_page=_ | ||
base on height | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,5 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/notional-labs/subnode/cmd" | ||
) | ||
|
||
func main() { | ||
cmd.Execute() | ||
Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.