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

TX preview - message #760

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Release built: _not released yet_

- Optimized `/statistics/validators/uptime` endpoint processing time.

### API Changes
- Added support for the missing `message` and `flags.disable_auth_checks` properties in the `/transaction/preview` endpoint request.

### Database changes
- Replaced relationship-related columns (`*_entity_id`) in the `entities` table with more generic collection implementation using `correlated_entity_*` columns.
- Replaced per-epoch validator emissions (`validator_emission_statistics` table) with their cumulative statistics (`validator_cumulative_emission_history` table).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
* permissions under this License.
*/

using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Linq;
using RadixDlt.NetworkGateway.Abstractions.CoreCommunications;
using RadixDlt.NetworkGateway.Abstractions.Extensions;
using RadixDlt.NetworkGateway.Abstractions.Network;
Expand All @@ -87,12 +89,14 @@ internal class TransactionPreviewService : ITransactionPreviewService
private readonly INetworkConfigurationProvider _networkConfigurationProvider;
private readonly ICoreApiProvider _coreApiProvider;
private readonly IEnumerable<ITransactionPreviewServiceObserver> _observers;
private readonly ILogger _logger;

public TransactionPreviewService(INetworkConfigurationProvider networkConfigurationProvider, ICoreApiProvider coreApiProvider, IEnumerable<ITransactionPreviewServiceObserver> observers)
public TransactionPreviewService(INetworkConfigurationProvider networkConfigurationProvider, ICoreApiProvider coreApiProvider, IEnumerable<ITransactionPreviewServiceObserver> observers, ILogger<TransactionPreviewService> logger)
{
_networkConfigurationProvider = networkConfigurationProvider;
_coreApiProvider = coreApiProvider;
_observers = observers;
_logger = logger;
}

public async Task<GatewayModel.TransactionPreviewResponse> HandlePreviewRequest(GatewayModel.TransactionPreviewRequest request, CancellationToken token = default)
Expand All @@ -119,8 +123,9 @@ public TransactionPreviewService(INetworkConfigurationProvider networkConfigurat

private async Task<GatewayModel.TransactionPreviewResponse> HandlePreviewAndCreateResponse(GatewayModel.TransactionPreviewRequest request, CancellationToken token)
{
CoreModel.PublicKey ToCoreModel(GatewayModel.PublicKey publicKey) => publicKey switch
CoreModel.PublicKey? MapPublicKey(GatewayModel.PublicKey? publicKey) => publicKey switch
{
null => null,
GatewayModel.PublicKeyEcdsaSecp256k1 ecdsaSecp256K1 => new CoreModel.EcdsaSecp256k1PublicKey(ecdsaSecp256K1.KeyHex),
GatewayModel.PublicKeyEddsaEd25519 eddsaEd25519 => new CoreModel.EddsaEd25519PublicKey(eddsaEd25519.KeyHex),
_ => throw new UnreachableException($"Didn't expect {publicKey.GetType().Name} type"),
Expand All @@ -129,19 +134,37 @@ public TransactionPreviewService(INetworkConfigurationProvider networkConfigurat
var coreRequestFlags = new CoreModel.TransactionPreviewRequestFlags(
useFreeCredit: request.Flags.UseFreeCredit,
assumeAllSignatureProofs: request.Flags.AssumeAllSignatureProofs,
skipEpochCheck: request.Flags.SkipEpochCheck);
skipEpochCheck: request.Flags.SkipEpochCheck,
disableAuthChecks: request.Flags.DisableAuthChecks);

CoreModel.TransactionMessage? message = null;

if (request.Message != null)
{
try
{
message = (request.Message as JObject)?.ToObject<CoreModel.TransactionMessage>();
}
catch (Exception ex)
{
_logger.LogError(ex, "Unable to parse TX message");

throw InvalidRequestException.FromOtherError("Unable to parse TX message");
}
}

var coreRequest = new CoreModel.TransactionPreviewRequest(
network: (await _networkConfigurationProvider.GetNetworkConfiguration(token)).Name,
manifest: request.Manifest,
blobsHex: request.BlobsHex,
startEpochInclusive: request.StartEpochInclusive,
endEpochExclusive: request.EndEpochExclusive,
notaryPublicKey: request.NotaryPublicKey != null ? ToCoreModel(request.NotaryPublicKey) : null,
notaryPublicKey: MapPublicKey(request.NotaryPublicKey),
notaryIsSignatory: request.NotaryIsSignatory,
tipPercentage: request.TipPercentage,
nonce: request.Nonce,
signerPublicKeys: request.SignerPublicKeys.Select(ToCoreModel).ToList(),
signerPublicKeys: request.SignerPublicKeys.Select(MapPublicKey).ToList(),
message: message,
flags: coreRequestFlags);

var result = await CoreApiErrorWrapper.ResultOrError<CoreModel.TransactionPreviewResponse, CoreModel.BasicErrorResponse>(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3353,6 +3353,10 @@ components:
items:
$ref: "#/components/schemas/PublicKey"
description: A list of public keys to be used as transaction signers
message:
PawelPawelec-RDX marked this conversation as resolved.
Show resolved Hide resolved
type: object
description: |
This type is defined in the Core API as `TransactionMessage`. See the Core API documentation for more details.
flags:
type: object
required:
Expand All @@ -3366,6 +3370,8 @@ components:
type: boolean
skip_epoch_check:
type: boolean
disable_auth_checks:
type: boolean
TransactionPreviewResponse:
type: object
required:
Expand Down Expand Up @@ -3841,7 +3847,7 @@ components:
$ref: "#/components/schemas/StateEntityDetailsOptIns"
addresses:
type: array
description: limited to max 100 items.
description: limited to max 20 items.
items:
$ref: "#/components/schemas/Address"
aggregation_level:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected StateEntityDetailsRequest() { }
/// </summary>
/// <param name="atLedgerState">atLedgerState.</param>
/// <param name="optIns">optIns.</param>
/// <param name="addresses">limited to max 100 items. (required).</param>
/// <param name="addresses">limited to max 20 items. (required).</param>
/// <param name="aggregationLevel">aggregationLevel.</param>
public StateEntityDetailsRequest(LedgerStateSelector atLedgerState = default(LedgerStateSelector), StateEntityDetailsOptIns optIns = default(StateEntityDetailsOptIns), List<string> addresses = default(List<string>), ResourceAggregationLevel? aggregationLevel = default(ResourceAggregationLevel?))
{
Expand Down Expand Up @@ -139,9 +139,9 @@ protected StateEntityDetailsRequest() { }
public StateEntityDetailsOptIns OptIns { get; set; }

/// <summary>
/// limited to max 100 items.
/// limited to max 20 items.
/// </summary>
/// <value>limited to max 100 items.</value>
/// <value>limited to max 20 items.</value>
[DataMember(Name = "addresses", IsRequired = true, EmitDefaultValue = true)]
public List<string> Addresses { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected StateEntityDetailsRequestAllOf() { }
/// Initializes a new instance of the <see cref="StateEntityDetailsRequestAllOf" /> class.
/// </summary>
/// <param name="optIns">optIns.</param>
/// <param name="addresses">limited to max 100 items. (required).</param>
/// <param name="addresses">limited to max 20 items. (required).</param>
/// <param name="aggregationLevel">aggregationLevel.</param>
public StateEntityDetailsRequestAllOf(StateEntityDetailsOptIns optIns = default(StateEntityDetailsOptIns), List<string> addresses = default(List<string>), ResourceAggregationLevel? aggregationLevel = default(ResourceAggregationLevel?))
{
Expand All @@ -131,9 +131,9 @@ protected StateEntityDetailsRequestAllOf() { }
public StateEntityDetailsOptIns OptIns { get; set; }

/// <summary>
/// limited to max 100 items.
/// limited to max 20 items.
/// </summary>
/// <value>limited to max 100 items.</value>
/// <value>limited to max 20 items.</value>
[DataMember(Name = "addresses", IsRequired = true, EmitDefaultValue = true)]
public List<string> Addresses { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ protected TransactionPreviewRequest() { }
/// <param name="tipPercentage">An integer between &#x60;0&#x60; and &#x60;65535&#x60;, giving the validator tip as a percentage amount. A value of &#x60;1&#x60; corresponds to 1% of the fee. (required).</param>
/// <param name="nonce">A decimal-string-encoded integer between &#x60;0&#x60; and &#x60;2^32 - 1&#x60;, used to ensure the transaction intent is unique. (required).</param>
/// <param name="signerPublicKeys">A list of public keys to be used as transaction signers (required).</param>
/// <param name="message">This type is defined in the Core API as &#x60;TransactionMessage&#x60;. See the Core API documentation for more details. .</param>
/// <param name="flags">flags (required).</param>
public TransactionPreviewRequest(string manifest = default(string), List<string> blobsHex = default(List<string>), long startEpochInclusive = default(long), long endEpochExclusive = default(long), PublicKey notaryPublicKey = default(PublicKey), bool notaryIsSignatory = default(bool), int tipPercentage = default(int), long nonce = default(long), List<PublicKey> signerPublicKeys = default(List<PublicKey>), TransactionPreviewRequestFlags flags = default(TransactionPreviewRequestFlags))
public TransactionPreviewRequest(string manifest = default(string), List<string> blobsHex = default(List<string>), long startEpochInclusive = default(long), long endEpochExclusive = default(long), PublicKey notaryPublicKey = default(PublicKey), bool notaryIsSignatory = default(bool), int tipPercentage = default(int), long nonce = default(long), List<PublicKey> signerPublicKeys = default(List<PublicKey>), Object message = default(Object), TransactionPreviewRequestFlags flags = default(TransactionPreviewRequestFlags))
{
// to ensure "manifest" is required (not null)
if (manifest == null)
Expand All @@ -140,6 +141,7 @@ protected TransactionPreviewRequest() { }
this.BlobsHex = blobsHex;
this.NotaryPublicKey = notaryPublicKey;
this.NotaryIsSignatory = notaryIsSignatory;
this.Message = message;
}

/// <summary>
Expand Down Expand Up @@ -204,6 +206,13 @@ protected TransactionPreviewRequest() { }
[DataMember(Name = "signer_public_keys", IsRequired = true, EmitDefaultValue = true)]
public List<PublicKey> SignerPublicKeys { get; set; }

/// <summary>
/// This type is defined in the Core API as &#x60;TransactionMessage&#x60;. See the Core API documentation for more details.
/// </summary>
/// <value>This type is defined in the Core API as &#x60;TransactionMessage&#x60;. See the Core API documentation for more details. </value>
[DataMember(Name = "message", EmitDefaultValue = true)]
public Object Message { get; set; }

/// <summary>
/// Gets or Sets Flags
/// </summary>
Expand All @@ -227,6 +236,7 @@ public override string ToString()
sb.Append(" TipPercentage: ").Append(TipPercentage).Append("\n");
sb.Append(" Nonce: ").Append(Nonce).Append("\n");
sb.Append(" SignerPublicKeys: ").Append(SignerPublicKeys).Append("\n");
sb.Append(" Message: ").Append(Message).Append("\n");
sb.Append(" Flags: ").Append(Flags).Append("\n");
sb.Append("}\n");
return sb.ToString();
Expand Down Expand Up @@ -305,6 +315,11 @@ public bool Equals(TransactionPreviewRequest input)
input.SignerPublicKeys != null &&
this.SignerPublicKeys.SequenceEqual(input.SignerPublicKeys)
) &&
(
this.Message == input.Message ||
(this.Message != null &&
this.Message.Equals(input.Message))
) &&
(
this.Flags == input.Flags ||
(this.Flags != null &&
Expand Down Expand Up @@ -342,6 +357,10 @@ public override int GetHashCode()
{
hashCode = (hashCode * 59) + this.SignerPublicKeys.GetHashCode();
}
if (this.Message != null)
{
hashCode = (hashCode * 59) + this.Message.GetHashCode();
}
if (this.Flags != null)
{
hashCode = (hashCode * 59) + this.Flags.GetHashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ protected TransactionPreviewRequestFlags() { }
/// <param name="useFreeCredit">useFreeCredit (required).</param>
/// <param name="assumeAllSignatureProofs">assumeAllSignatureProofs (required).</param>
/// <param name="skipEpochCheck">skipEpochCheck (required).</param>
public TransactionPreviewRequestFlags(bool useFreeCredit = default(bool), bool assumeAllSignatureProofs = default(bool), bool skipEpochCheck = default(bool))
/// <param name="disableAuthChecks">disableAuthChecks.</param>
public TransactionPreviewRequestFlags(bool useFreeCredit = default(bool), bool assumeAllSignatureProofs = default(bool), bool skipEpochCheck = default(bool), bool disableAuthChecks = default(bool))
{
this.UseFreeCredit = useFreeCredit;
this.AssumeAllSignatureProofs = assumeAllSignatureProofs;
this.SkipEpochCheck = skipEpochCheck;
this.DisableAuthChecks = disableAuthChecks;
}

/// <summary>
Expand All @@ -131,6 +133,12 @@ protected TransactionPreviewRequestFlags() { }
[DataMember(Name = "skip_epoch_check", IsRequired = true, EmitDefaultValue = true)]
public bool SkipEpochCheck { get; set; }

/// <summary>
/// Gets or Sets DisableAuthChecks
/// </summary>
[DataMember(Name = "disable_auth_checks", EmitDefaultValue = true)]
public bool DisableAuthChecks { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
Expand All @@ -142,6 +150,7 @@ public override string ToString()
sb.Append(" UseFreeCredit: ").Append(UseFreeCredit).Append("\n");
sb.Append(" AssumeAllSignatureProofs: ").Append(AssumeAllSignatureProofs).Append("\n");
sb.Append(" SkipEpochCheck: ").Append(SkipEpochCheck).Append("\n");
sb.Append(" DisableAuthChecks: ").Append(DisableAuthChecks).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand Down Expand Up @@ -188,6 +197,10 @@ public bool Equals(TransactionPreviewRequestFlags input)
(
this.SkipEpochCheck == input.SkipEpochCheck ||
this.SkipEpochCheck.Equals(input.SkipEpochCheck)
) &&
(
this.DisableAuthChecks == input.DisableAuthChecks ||
this.DisableAuthChecks.Equals(input.DisableAuthChecks)
);
}

Expand All @@ -203,6 +216,7 @@ public override int GetHashCode()
hashCode = (hashCode * 59) + this.UseFreeCredit.GetHashCode();
hashCode = (hashCode * 59) + this.AssumeAllSignatureProofs.GetHashCode();
hashCode = (hashCode * 59) + this.SkipEpochCheck.GetHashCode();
hashCode = (hashCode * 59) + this.DisableAuthChecks.GetHashCode();
return hashCode;
}
}
Expand Down
Loading