Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(grpc): add fee config to get node info api response #1561

2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config,
if conf.GRPC.BasicAuth != "" {
enableHTTPAuth = true
}
grpcServer := grpc.NewServer(conf.GRPC, st, syn, net, consMgr, walletMgr)
grpcServer := grpc.NewServer(conf.GRPC, st, syn, net, consMgr, walletMgr, conf.TxPool)
Copy link
Contributor

@Ja7ad Ja7ad Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b00f What you think we pass just conf instead part of configuration to gRPC?

Copy link
Collaborator

@b00f b00f Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering maybe we can find a better way

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think out of box; gRPC almost have everything. Right?
Why don't we simply give him Node.

Copy link
Contributor

@Ja7ad Ja7ad Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can give public access to configuration via node?

Copy link
Contributor Author

@alidevjimmy alidevjimmy Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node itself depends on gRPC

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node has all modules...

Copy link
Contributor Author

@alidevjimmy alidevjimmy Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we pass node to gRPC we will encounter cycle import.
I suggest passing conf as Javad said.

httpServer := http.NewServer(conf.HTTP, enableHTTPAuth)
jsonrpcServer := jsonrpc.NewServer(conf.JSONRPC)
nanomsgServer := nanomsg.NewServer(conf.Nanomsg, eventCh)
Expand Down
5 changes: 5 additions & 0 deletions wallet/wallet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/pactus-project/pactus/crypto/bls"
"github.com/pactus-project/pactus/genesis"
"github.com/pactus-project/pactus/state"
"github.com/pactus-project/pactus/txpool"
"github.com/pactus-project/pactus/types/account"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/types/validator"
Expand Down Expand Up @@ -45,11 +46,15 @@ func setup(t *testing.T) *testData {
WalletsDir: util.TempDirPath(),
ChainType: genesis.Mainnet,
}

txpoolConf := txpool.DefaultConfig()

mockState := state.MockingState(ts)
gRPCServer := grpc.NewServer(
grpcConf, mockState,
nil, nil,
nil, wallet.NewWalletManager(walletMgrConf),
txpoolConf,
)

assert.NoError(t, gRPCServer.StartServer())
Expand Down
4 changes: 3 additions & 1 deletion www/grpc/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package grpc

import "github.com/pactus-project/pactus/util/htpasswd"
import (
alidevjimmy marked this conversation as resolved.
Show resolved Hide resolved
"github.com/pactus-project/pactus/util/htpasswd"
)

type Config struct {
Enable bool `toml:"enable"`
Expand Down
91 changes: 91 additions & 0 deletions www/grpc/gen/dart/network.pb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage {
..pPS(9, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'protocols')
..a<$core.double>(13, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'clockOffset', $pb.PbFieldType.OD)
..aOM<ConnectionInfo>(14, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'connectionInfo', subBuilder: ConnectionInfo.create)
..aOM<FeeConfig>(15, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'fee', subBuilder: FeeConfig.create)
..hasRequiredFields = false
;

Expand All @@ -201,6 +202,7 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage {
$core.Iterable<$core.String>? protocols,
$core.double? clockOffset,
ConnectionInfo? connectionInfo,
FeeConfig? fee,
}) {
final _result = create();
if (moniker != null) {
Expand Down Expand Up @@ -236,6 +238,9 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage {
if (connectionInfo != null) {
_result.connectionInfo = connectionInfo;
}
if (fee != null) {
_result.fee = fee;
}
return _result;
}
factory GetNodeInfoResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
Expand Down Expand Up @@ -347,6 +352,17 @@ class GetNodeInfoResponse extends $pb.GeneratedMessage {
void clearConnectionInfo() => clearField(14);
@$pb.TagNumber(14)
ConnectionInfo ensureConnectionInfo() => $_ensure(10);

@$pb.TagNumber(15)
FeeConfig get fee => $_getN(11);
@$pb.TagNumber(15)
set fee(FeeConfig v) { setField(15, v); }
@$pb.TagNumber(15)
$core.bool hasFee() => $_has(11);
@$pb.TagNumber(15)
void clearFee() => clearField(15);
@$pb.TagNumber(15)
FeeConfig ensureFee() => $_ensure(11);
}

class PeerInfo extends $pb.GeneratedMessage {
Expand Down Expand Up @@ -837,6 +853,81 @@ class CounterInfo extends $pb.GeneratedMessage {
void clearBundles() => clearField(2);
}

class FeeConfig extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'FeeConfig', package: const $pb.PackageName(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'pactus'), createEmptyInstance: create)
..a<$core.double>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'fixedFee', $pb.PbFieldType.OD)
..a<$core.int>(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'dailyLimit', $pb.PbFieldType.OU3)
..a<$core.double>(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'unitPrice', $pb.PbFieldType.OD)
..hasRequiredFields = false
;

FeeConfig._() : super();
factory FeeConfig({
$core.double? fixedFee,
$core.int? dailyLimit,
$core.double? unitPrice,
}) {
final _result = create();
if (fixedFee != null) {
_result.fixedFee = fixedFee;
}
if (dailyLimit != null) {
_result.dailyLimit = dailyLimit;
}
if (unitPrice != null) {
_result.unitPrice = unitPrice;
}
return _result;
}
factory FeeConfig.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory FeeConfig.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.deepCopy] instead. '
'Will be removed in next major version')
FeeConfig clone() => FeeConfig()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
FeeConfig copyWith(void Function(FeeConfig) updates) => super.copyWith((message) => updates(message as FeeConfig)) as FeeConfig; // ignore: deprecated_member_use
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static FeeConfig create() => FeeConfig._();
FeeConfig createEmptyInstance() => create();
static $pb.PbList<FeeConfig> createRepeated() => $pb.PbList<FeeConfig>();
@$core.pragma('dart2js:noInline')
static FeeConfig getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<FeeConfig>(create);
static FeeConfig? _defaultInstance;

@$pb.TagNumber(1)
$core.double get fixedFee => $_getN(0);
@$pb.TagNumber(1)
set fixedFee($core.double v) { $_setDouble(0, v); }
@$pb.TagNumber(1)
$core.bool hasFixedFee() => $_has(0);
@$pb.TagNumber(1)
void clearFixedFee() => clearField(1);

@$pb.TagNumber(2)
$core.int get dailyLimit => $_getIZ(1);
@$pb.TagNumber(2)
set dailyLimit($core.int v) { $_setUnsignedInt32(1, v); }
@$pb.TagNumber(2)
$core.bool hasDailyLimit() => $_has(1);
@$pb.TagNumber(2)
void clearDailyLimit() => clearField(2);

@$pb.TagNumber(3)
$core.double get unitPrice => $_getN(2);
@$pb.TagNumber(3)
set unitPrice($core.double v) { $_setDouble(2, v); }
@$pb.TagNumber(3)
$core.bool hasUnitPrice() => $_has(2);
@$pb.TagNumber(3)
void clearUnitPrice() => clearField(3);
}

class NetworkApi {
$pb.RpcClient _client;
NetworkApi(this._client);
Expand Down
16 changes: 15 additions & 1 deletion www/grpc/gen/dart/network.pbjson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ const GetNodeInfoResponse$json = const {
const {'1': 'protocols', '3': 9, '4': 3, '5': 9, '10': 'protocols'},
const {'1': 'clock_offset', '3': 13, '4': 1, '5': 1, '10': 'clockOffset'},
const {'1': 'connection_info', '3': 14, '4': 1, '5': 11, '6': '.pactus.ConnectionInfo', '10': 'connectionInfo'},
const {'1': 'fee', '3': 15, '4': 1, '5': 11, '6': '.pactus.FeeConfig', '10': 'fee'},
],
};

/// Descriptor for `GetNodeInfoResponse`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List getNodeInfoResponseDescriptor = $convert.base64Decode('ChNHZXROb2RlSW5mb1Jlc3BvbnNlEhgKB21vbmlrZXIYASABKAlSB21vbmlrZXISFAoFYWdlbnQYAiABKAlSBWFnZW50EhcKB3BlZXJfaWQYAyABKAlSBnBlZXJJZBIdCgpzdGFydGVkX2F0GAQgASgEUglzdGFydGVkQXQSIgoMcmVhY2hhYmlsaXR5GAUgASgJUgxyZWFjaGFiaWxpdHkSGgoIc2VydmljZXMYBiABKAVSCHNlcnZpY2VzEiUKDnNlcnZpY2VzX25hbWVzGAcgASgJUg1zZXJ2aWNlc05hbWVzEh8KC2xvY2FsX2FkZHJzGAggAygJUgpsb2NhbEFkZHJzEhwKCXByb3RvY29scxgJIAMoCVIJcHJvdG9jb2xzEiEKDGNsb2NrX29mZnNldBgNIAEoAVILY2xvY2tPZmZzZXQSPwoPY29ubmVjdGlvbl9pbmZvGA4gASgLMhYucGFjdHVzLkNvbm5lY3Rpb25JbmZvUg5jb25uZWN0aW9uSW5mbw==');
final $typed_data.Uint8List getNodeInfoResponseDescriptor = $convert.base64Decode('ChNHZXROb2RlSW5mb1Jlc3BvbnNlEhgKB21vbmlrZXIYASABKAlSB21vbmlrZXISFAoFYWdlbnQYAiABKAlSBWFnZW50EhcKB3BlZXJfaWQYAyABKAlSBnBlZXJJZBIdCgpzdGFydGVkX2F0GAQgASgEUglzdGFydGVkQXQSIgoMcmVhY2hhYmlsaXR5GAUgASgJUgxyZWFjaGFiaWxpdHkSGgoIc2VydmljZXMYBiABKAVSCHNlcnZpY2VzEiUKDnNlcnZpY2VzX25hbWVzGAcgASgJUg1zZXJ2aWNlc05hbWVzEh8KC2xvY2FsX2FkZHJzGAggAygJUgpsb2NhbEFkZHJzEhwKCXByb3RvY29scxgJIAMoCVIJcHJvdG9jb2xzEiEKDGNsb2NrX29mZnNldBgNIAEoAVILY2xvY2tPZmZzZXQSPwoPY29ubmVjdGlvbl9pbmZvGA4gASgLMhYucGFjdHVzLkNvbm5lY3Rpb25JbmZvUg5jb25uZWN0aW9uSW5mbxIjCgNmZWUYDyABKAsyES5wYWN0dXMuRmVlQ29uZmlnUgNmZWU=');
@$core.Deprecated('Use peerInfoDescriptor instead')
const PeerInfo$json = const {
'1': 'PeerInfo',
Expand Down Expand Up @@ -142,6 +143,18 @@ const CounterInfo$json = const {

/// Descriptor for `CounterInfo`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List counterInfoDescriptor = $convert.base64Decode('CgtDb3VudGVySW5mbxIUCgVCeXRlcxgBIAEoBFIFQnl0ZXMSGAoHQnVuZGxlcxgCIAEoBFIHQnVuZGxlcw==');
@$core.Deprecated('Use feeConfigDescriptor instead')
const FeeConfig$json = const {
'1': 'FeeConfig',
'2': const [
const {'1': 'fixed_fee', '3': 1, '4': 1, '5': 1, '10': 'fixedFee'},
const {'1': 'daily_limit', '3': 2, '4': 1, '5': 13, '10': 'dailyLimit'},
const {'1': 'unit_price', '3': 3, '4': 1, '5': 1, '10': 'unitPrice'},
],
};

/// Descriptor for `FeeConfig`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List feeConfigDescriptor = $convert.base64Decode('CglGZWVDb25maWcSGwoJZml4ZWRfZmVlGAEgASgBUghmaXhlZEZlZRIfCgtkYWlseV9saW1pdBgCIAEoDVIKZGFpbHlMaW1pdBIdCgp1bml0X3ByaWNlGAMgASgBUgl1bml0UHJpY2U=');
const $core.Map<$core.String, $core.dynamic> NetworkServiceBase$json = const {
'1': 'Network',
'2': const [
Expand All @@ -162,6 +175,7 @@ const $core.Map<$core.String, $core.Map<$core.String, $core.dynamic>> NetworkSer
'.pactus.GetNodeInfoRequest': GetNodeInfoRequest$json,
'.pactus.GetNodeInfoResponse': GetNodeInfoResponse$json,
'.pactus.ConnectionInfo': ConnectionInfo$json,
'.pactus.FeeConfig': FeeConfig$json,
};

/// Descriptor for `Network`. Decode as a `google.protobuf.ServiceDescriptorProto`.
Expand Down
28 changes: 28 additions & 0 deletions www/grpc/gen/docs/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2622,6 +2622,34 @@ Message has no fields.
<td>
Number of outbound connections.
</td>
</tr>
<tr>
<td class="fw-bold">fee</td>
<td> FeeConfig</td>
<td>
Fee config of the node.
</td>
</tr>
<tr>
<td class="fw-bold">fee.fixed_fee</td>
<td> double</td>
<td>
Fixed fee for each transaction.
</td>
</tr>
<tr>
<td class="fw-bold">fee.daily_limit</td>
<td> uint32</td>
<td>
Number of bytes an account can send each day without paying a fee.
</td>
</tr>
<tr>
<td class="fw-bold">fee.unit_price</td>
<td> double</td>
<td>
Fee per byte in PAC.
</td>
</tr>
</tbody>
</table>
Expand Down
28 changes: 28 additions & 0 deletions www/grpc/gen/docs/json-rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2673,6 +2673,34 @@ Parameters has no fields.
<td>
Number of outbound connections.
</td>
</tr>
<tr>
<td class="fw-bold">fee</td>
<td> object</td>
<td>
Fee config of the node.
</td>
</tr>
<tr>
<td class="fw-bold">fee.fixed_fee</td>
<td> numeric</td>
<td>
Fixed fee for each transaction.
</td>
</tr>
<tr>
<td class="fw-bold">fee.daily_limit</td>
<td> numeric</td>
<td>
Number of bytes an account can send each day without paying a fee.
</td>
</tr>
<tr>
<td class="fw-bold">fee.unit_price</td>
<td> numeric</td>
<td>
Fee per byte in PAC.
</td>
</tr>
</tbody>
</table>
Expand Down
Loading
Loading