Skip to content

Commit 62a4d14

Browse files
committed
fixup! [GH-846] Added bootstrap-url parameter for simple initialization of archive node.
1 parent e5d6c8c commit 62a4d14

File tree

6 files changed

+39
-30
lines changed

6 files changed

+39
-30
lines changed

nil/client/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/NilFoundation/nil/nil/internal/contracts"
1515
"github.com/NilFoundation/nil/nil/internal/types"
1616
"github.com/NilFoundation/nil/nil/services/rpc/jsonrpc"
17+
rpctypes "github.com/NilFoundation/nil/nil/services/rpc/types"
1718
"github.com/NilFoundation/nil/nil/services/txnpool"
1819
)
1920

@@ -132,6 +133,8 @@ type Client interface {
132133

133134
// GetDebugContract retrieves smart contract with its data, such as code, storage and proof
134135
GetDebugContract(ctx context.Context, contractAddr types.Address, blockId any) (*jsonrpc.DebugRPCContract, error)
136+
137+
GetBootstrapConfig(ctx context.Context) (*rpctypes.BootstrapConfig, error)
135138
}
136139

137140
func EstimateFeeExternal(

nil/client/direct_client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/NilFoundation/nil/nil/services/rpc/jsonrpc"
1616
"github.com/NilFoundation/nil/nil/services/rpc/rawapi"
1717
"github.com/NilFoundation/nil/nil/services/rpc/transport"
18+
rpctypes "github.com/NilFoundation/nil/nil/services/rpc/types"
1819
)
1920

2021
// DirectClient is a client that interacts with the end api directly, without using the rpc server.
@@ -438,3 +439,7 @@ func (c *DirectClient) GetTxpoolStatus(ctx context.Context, shardId types.ShardI
438439
func (c *DirectClient) GetTxpoolContent(ctx context.Context, shardId types.ShardId) (jsonrpc.TxPoolContent, error) {
439440
return c.txPoolApi.GetTxpoolContent(ctx, shardId)
440441
}
442+
443+
func (c *DirectClient) GetBootstrapConfig(ctx context.Context) (*rpctypes.BootstrapConfig, error) {
444+
return c.debugApi.GetBootstrapConfig(ctx)
445+
}

nil/client/rpc/client.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/NilFoundation/nil/nil/internal/types"
2626
"github.com/NilFoundation/nil/nil/services/rpc/jsonrpc"
2727
"github.com/NilFoundation/nil/nil/services/rpc/transport"
28+
rpctypes "github.com/NilFoundation/nil/nil/services/rpc/types"
2829
)
2930

3031
// CallError represents an error that occurs during a remote procedure call,
@@ -79,6 +80,7 @@ const (
7980
Debug_getBlockByHash = "debug_getBlockByHash"
8081
Debug_getBlockByNumber = "debug_getBlockByNumber"
8182
Debug_getContract = "debug_getContract"
83+
Debug_getBootstrapConfig = "debug_getBootstrapConfig"
8284
Web3_clientVersion = "web3_clientVersion"
8385
Dev_doPanicOnShard = "dev_doPanicOnShard"
8486
Txpool_getTxpoolStatus = "txpool_getTxpoolStatus"
@@ -951,6 +953,18 @@ func (c *Client) DoPanicOnShard(ctx context.Context, shardId types.ShardId) (uin
951953
return 0, err
952954
}
953955

956+
func (c *Client) GetTxpoolStatus(ctx context.Context, shardId types.ShardId) (jsonrpc.TxPoolStatus, error) {
957+
return simpleCall[jsonrpc.TxPoolStatus](ctx, c, Txpool_getTxpoolStatus, shardId)
958+
}
959+
960+
func (c *Client) GetTxpoolContent(ctx context.Context, shardId types.ShardId) (jsonrpc.TxPoolContent, error) {
961+
return simpleCall[jsonrpc.TxPoolContent](ctx, c, Txpool_getTxpoolContent, shardId)
962+
}
963+
964+
func (c *Client) GetBootstrapConfig(ctx context.Context) (*rpctypes.BootstrapConfig, error) {
965+
return simpleCall[*rpctypes.BootstrapConfig](ctx, c, Debug_getBootstrapConfig)
966+
}
967+
954968
func simpleCall[ReturnType any](ctx context.Context, c *Client, method string, params ...any) (ReturnType, error) {
955969
res, err := c.call(ctx, method, params...)
956970
var result ReturnType
@@ -977,11 +991,3 @@ func simpleCallUint64[ReturnType ~uint64](
977991
}
978992
return ReturnType(result), err
979993
}
980-
981-
func (c *Client) GetTxpoolStatus(ctx context.Context, shardId types.ShardId) (jsonrpc.TxPoolStatus, error) {
982-
return simpleCall[jsonrpc.TxPoolStatus](ctx, c, Txpool_getTxpoolStatus, shardId)
983-
}
984-
985-
func (c *Client) GetTxpoolContent(ctx context.Context, shardId types.ShardId) (jsonrpc.TxPoolContent, error) {
986-
return simpleCall[jsonrpc.TxPoolContent](ctx, c, Txpool_getTxpoolContent, shardId)
987-
}

nil/cmd/nild/main.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package main
22

33
import (
44
"context"
5-
"encoding/json"
65
"errors"
76
"os"
87
"time"
@@ -22,7 +21,6 @@ import (
2221
"github.com/NilFoundation/nil/nil/services/indexer"
2322
"github.com/NilFoundation/nil/nil/services/nilservice"
2423
"github.com/NilFoundation/nil/nil/services/rpc/transport"
25-
rpctypes "github.com/NilFoundation/nil/nil/services/rpc/types"
2624
"github.com/spf13/cobra"
2725
"github.com/spf13/pflag"
2826
)
@@ -104,19 +102,16 @@ func addBasicFlags(fset *pflag.FlagSet, cfg *nildconfig.Config) {
104102
&cfg.CollatorTickPeriodMs, "collator-tick-ms", cfg.CollatorTickPeriodMs, "collator tick period in milliseconds")
105103
}
106104

107-
func doBootstrapRequestAndPatchConfig(bootstrapUrl string, cfg *nildconfig.Config, logger logging.Logger) error {
108-
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
105+
func doBootstrapRequestAndPatchConfig(
106+
ctx context.Context,
107+
bootstrapUrl string,
108+
cfg *nildconfig.Config,
109+
logger logging.Logger,
110+
) error {
111+
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
109112
defer cancel()
110113

111-
client := rpc_client.NewRawClient(bootstrapUrl, logger)
112-
response, err := client.RawCall(ctx, "debug_getBootstrapConfig")
113-
if err != nil {
114-
logger.Error().Err(err).Msg("failed to fetch bootstrap config")
115-
return err
116-
}
117-
118-
var bootstrapConfig rpctypes.BootstrapConfig
119-
err = json.Unmarshal(response, &bootstrapConfig)
114+
bootstrapConfig, err := rpc_client.NewClient(bootstrapUrl, logger).GetBootstrapConfig(ctx)
120115
if err != nil {
121116
return err
122117
}
@@ -233,7 +228,7 @@ func parseArgs(logger logging.Logger) *nildconfig.Config {
233228
cfg.RunMode = nilservice.ArchiveRunMode
234229

235230
if bootstrapUrl != "" {
236-
return doBootstrapRequestAndPatchConfig(bootstrapUrl, cfg, logger)
231+
return doBootstrapRequestAndPatchConfig(cmd.Context(), bootstrapUrl, cfg, logger)
237232
}
238233

239234
return nil

nil/internal/network/addr_info.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,12 @@ func (a *AddrInfo) UnmarshalText(text []byte) error {
5151
return a.Set(string(text))
5252
}
5353

54-
func (a AddrInfo) MarshalYAML() (any, error) {
55-
return a.String(), nil
54+
func (a *AddrInfo) MarshalYAML() (any, error) {
55+
return a.MarshalText()
5656
}
5757

5858
func (a *AddrInfo) UnmarshalYAML(value *yaml.Node) error {
59-
var str string
60-
if err := value.Decode(&str); err != nil {
61-
return err
62-
}
63-
return a.Set(str)
59+
return a.UnmarshalText([]byte(value.Value))
6460
}
6561

6662
type AddrInfoSlice = common.PValueSlice[*AddrInfo, AddrInfo]

nil/internal/network/host.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ func newHost(ctx context.Context, conf *Config) (Host, logging.Logger, error) {
8989
}
9090

9191
if conf.ServeRelay {
92-
options = append(options, libp2p.EnableRelayService(relay.WithInfiniteLimits()))
92+
options = append(options, libp2p.EnableRelayService(
93+
// We temporarily disable the limitation because proxying traffic through a relay is the simplest
94+
// way to make the whole system work. Later we should study EnableAutoNATv2 and
95+
// EnableHolePunching more carefully to move to direct peer-to-peer connections.
96+
relay.WithInfiniteLimits()))
9397

9498
// todo: remove it after relay is tested
9599
// this is to make sure that the relay is not disabled

0 commit comments

Comments
 (0)