Skip to content

Commit

Permalink
Merge pull request #511 from NilFoundation/enable-faucet-in-rpc-node
Browse files Browse the repository at this point in the history
Enable faucet service in RPC node
  • Loading branch information
olegrok authored Mar 10, 2025
2 parents c71226b + 0b97fd3 commit e25b80d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
13 changes: 1 addition & 12 deletions nil/client/direct_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/NilFoundation/nil/nil/services/rpc/jsonrpc"
"github.com/NilFoundation/nil/nil/services/rpc/rawapi"
"github.com/NilFoundation/nil/nil/services/rpc/transport"
"github.com/NilFoundation/nil/nil/services/txnpool"
"github.com/rs/zerolog"
)

Expand All @@ -27,17 +26,7 @@ type DirectClient struct {

var _ Client = (*DirectClient)(nil)

func NewEthClient(ctx context.Context, db db.ReadOnlyDB, nShards types.ShardId, txnPools map[types.ShardId]txnpool.Pool, logger zerolog.Logger) (*DirectClient, error) {
var err error
localShardApis := make(map[types.ShardId]rawapi.ShardApi)
for shardId := range nShards {
localShardApis[shardId], err = rawapi.NewLocalRawApiAccessor(shardId, rawapi.NewLocalShardApi(shardId, db, txnPools[shardId]))
if err != nil {
return nil, err
}
}
localApi := rawapi.NewNodeApiOverShardApis(localShardApis)

func NewEthClient(ctx context.Context, db db.ReadOnlyDB, localApi *rawapi.NodeApiOverShardApis, logger zerolog.Logger) (*DirectClient, error) {
ethApi := jsonrpc.NewEthAPI(ctx, localApi, db, true, false)
debugApi := jsonrpc.NewDebugAPI(localApi, logger)
dbApi := jsonrpc.NewDbAPI(db, logger)
Expand Down
2 changes: 1 addition & 1 deletion nil/services/nilservice/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (c *Config) IsShardActive(shardId types.ShardId) bool {
}

func (c *Config) IsFaucetApiEnabled() bool {
return c.RunMode == NormalRunMode && !c.SplitShards
return (c.RunMode == NormalRunMode || c.RunMode == RpcRunMode) && !c.SplitShards
}

func (c *Config) ShouldStartCometa() bool {
Expand Down
2 changes: 1 addition & 1 deletion nil/services/nilservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ func CreateNode(ctx context.Context, name string, cfg *Config, database db.DB, i

var cl client.Client
if cfg.Cometa != nil || cfg.IsFaucetApiEnabled() {
cl, err = client.NewEthClient(ctx, database, types.ShardId(cfg.NShards), txnPools, logger)
cl, err = client.NewEthClient(ctx, database, rawApi, logger)
if err != nil {
return fmt.Errorf("failed to create node client: %w", err)
}
Expand Down
10 changes: 9 additions & 1 deletion nil/tests/rpc_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/NilFoundation/nil/nil/internal/types"
"github.com/NilFoundation/nil/nil/services/nilservice"
"github.com/NilFoundation/nil/nil/services/rpc/jsonrpc"
"github.com/NilFoundation/nil/nil/services/rpc/rawapi"
"github.com/NilFoundation/nil/nil/services/rpc/transport"
"github.com/rs/zerolog"
)
Expand Down Expand Up @@ -111,7 +112,14 @@ func (s *RpcSuite) Start(cfg *nilservice.Config) {

if cfg.RunMode == nilservice.CollatorsOnlyRunMode {
service := <-serviceInterop
c, err := client.NewEthClient(s.Context, s.Db, types.ShardId(s.ShardsNum), service.TxnPools, zerolog.New(os.Stderr))
localShardApis := make(map[types.ShardId]rawapi.ShardApi)
for shardId := range types.ShardId(s.ShardsNum) {
var err error
localShardApis[shardId], err = rawapi.NewLocalRawApiAccessor(shardId, rawapi.NewLocalShardApi(shardId, s.Db, service.TxnPools[shardId]))
s.Require().NoError(err)
}
localApi := rawapi.NewNodeApiOverShardApis(localShardApis)
c, err := client.NewEthClient(s.Context, s.Db, localApi, zerolog.New(os.Stderr))
s.Require().NoError(err)
s.Client = c
} else {
Expand Down

0 comments on commit e25b80d

Please sign in to comment.