From 883d44680e454fab35e3c6def2697b4bcfff5485 Mon Sep 17 00:00:00 2001 From: David Edey Date: Sat, 29 Jul 2023 13:16:34 +0100 Subject: [PATCH 1/3] fix: Add active validators as resolved entities --- .../LedgerExtension/PostgresLedgerExtenderService.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/RadixDlt.NetworkGateway.PostgresIntegration/LedgerExtension/PostgresLedgerExtenderService.cs b/src/RadixDlt.NetworkGateway.PostgresIntegration/LedgerExtension/PostgresLedgerExtenderService.cs index 73e08fd07..836935447 100644 --- a/src/RadixDlt.NetworkGateway.PostgresIntegration/LedgerExtension/PostgresLedgerExtenderService.cs +++ b/src/RadixDlt.NetworkGateway.PostgresIntegration/LedgerExtension/PostgresLedgerExtenderService.cs @@ -479,6 +479,14 @@ private async Task ProcessTransactions(ReadWriteDbContext db e.Schema = packageSchema.Value.Schema.SborData.ToJson(); }); } + + if (substateData is CoreModel.ConsensusManagerFieldCurrentValidatorSetSubstate currentValidatorSet) + { + foreach (var activeValidator in currentValidatorSet.Value.ValidatorSet) + { + referencedEntities.GetOrAdd((EntityAddress)activeValidator.Address, ea => new ReferencedEntity(ea, CoreModel.EntityType.GlobalValidator, stateVersion)); + } + } } foreach (var deletedSubstate in stateUpdates.DeletedSubstates) From cf1feb09c79bd2ecb9fe6e036f508d4522c0bcb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=81abu=C5=9B?= Date: Mon, 31 Jul 2023 10:07:57 +0200 Subject: [PATCH 2/3] Added missing IEntityAddressPointers --- ...ManagerFieldCurrentValidatorSetSubstate.cs | 76 +++++++++++++++++++ ...sensusManagerFieldValidatorRewardsValue.cs | 75 ++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 src/RadixDlt.CoreApiSdk/Model/ConsensusManagerFieldCurrentValidatorSetSubstate.cs create mode 100644 src/RadixDlt.CoreApiSdk/Model/ConsensusManagerFieldValidatorRewardsValue.cs diff --git a/src/RadixDlt.CoreApiSdk/Model/ConsensusManagerFieldCurrentValidatorSetSubstate.cs b/src/RadixDlt.CoreApiSdk/Model/ConsensusManagerFieldCurrentValidatorSetSubstate.cs new file mode 100644 index 000000000..45220b25c --- /dev/null +++ b/src/RadixDlt.CoreApiSdk/Model/ConsensusManagerFieldCurrentValidatorSetSubstate.cs @@ -0,0 +1,76 @@ +/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands). + * + * Licensed under the Radix License, Version 1.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at: + * + * radixfoundation.org/licenses/LICENSE-v1 + * + * The Licensor hereby grants permission for the Canonical version of the Work to be + * published, distributed and used under or by reference to the Licensor’s trademark + * Radix ® and use of any unregistered trade names, logos or get-up. + * + * The Licensor provides the Work (and each Contributor provides its Contributions) on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, + * including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, + * MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. + * + * Whilst the Work is capable of being deployed, used and adopted (instantiated) to create + * a distributed ledger it is your responsibility to test and validate the code, together + * with all logic and performance of that code under all foreseeable scenarios. + * + * The Licensor does not make or purport to make and hereby excludes liability for all + * and any representation, warranty or undertaking in any form whatsoever, whether express + * or implied, to any entity or person, including any representation, warranty or + * undertaking, as to the functionality security use, value or other characteristics of + * any distributed ledger nor in respect the functioning or value of any tokens which may + * be created stored or transferred using the Work. The Licensor does not warrant that the + * Work or any use of the Work complies with any law or regulation in any territory where + * it may be implemented or used or that it will be appropriate for any specific purpose. + * + * Neither the licensor nor any current or former employees, officers, directors, partners, + * trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor + * shall be liable for any direct or indirect, special, incidental, consequential or other + * losses of any kind, in tort, contract or otherwise (including but not limited to loss + * of revenue, income or profits, or loss of use or data, or loss of reputation, or loss + * of any economic or other opportunity of whatsoever nature or howsoever arising), arising + * out of or in connection with (without limitation of any use, misuse, of any ledger system + * or use made or its functionality or any performance or operation of any code or protocol + * caused by bugs or programming or logic errors or otherwise); + * + * A. any offer, purchase, holding, use, sale, exchange or transmission of any + * cryptographic keys, tokens or assets created, exchanged, stored or arising from any + * interaction with the Work; + * + * B. any failure in a transmission or loss of any token or assets keys or other digital + * artefacts due to errors in transmission; + * + * C. bugs, hacks, logic errors or faults in the Work or any communication; + * + * D. system software or apparatus including but not limited to losses caused by errors + * in holding or transmitting tokens by any third-party; + * + * E. breaches or failure of security including hacker attacks, loss or disclosure of + * password, loss of private key, unauthorised use or misuse of such passwords or keys; + * + * F. any losses including loss of anticipated savings or other benefits resulting from + * use of the Work or any changes to the Work (however implemented). + * + * You are solely responsible for; testing, validating and evaluation of all operation + * logic, functionality, security and appropriateness of using the Work for any commercial + * or non-commercial purpose and for any reproduction or redistribution by You of the + * Work. You assume all risks associated with Your use of the Work and the exercise of + * permissions under this License. + */ + +using System.Collections.Generic; +using System.Linq; + +namespace RadixDlt.CoreApiSdk.Model; + +public partial class ConsensusManagerFieldCurrentValidatorSetSubstate : IEntityAddressPointer +{ + public IEnumerable GetEntityAddresses() + { + return Value.ValidatorSet.Select(vs => vs.Address); + } +} diff --git a/src/RadixDlt.CoreApiSdk/Model/ConsensusManagerFieldValidatorRewardsValue.cs b/src/RadixDlt.CoreApiSdk/Model/ConsensusManagerFieldValidatorRewardsValue.cs new file mode 100644 index 000000000..75766b2d2 --- /dev/null +++ b/src/RadixDlt.CoreApiSdk/Model/ConsensusManagerFieldValidatorRewardsValue.cs @@ -0,0 +1,75 @@ +/* Copyright 2021 Radix Publishing Ltd incorporated in Jersey (Channel Islands). + * + * Licensed under the Radix License, Version 1.0 (the "License"); you may not use this + * file except in compliance with the License. You may obtain a copy of the License at: + * + * radixfoundation.org/licenses/LICENSE-v1 + * + * The Licensor hereby grants permission for the Canonical version of the Work to be + * published, distributed and used under or by reference to the Licensor’s trademark + * Radix ® and use of any unregistered trade names, logos or get-up. + * + * The Licensor provides the Work (and each Contributor provides its Contributions) on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, + * including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, + * MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. + * + * Whilst the Work is capable of being deployed, used and adopted (instantiated) to create + * a distributed ledger it is your responsibility to test and validate the code, together + * with all logic and performance of that code under all foreseeable scenarios. + * + * The Licensor does not make or purport to make and hereby excludes liability for all + * and any representation, warranty or undertaking in any form whatsoever, whether express + * or implied, to any entity or person, including any representation, warranty or + * undertaking, as to the functionality security use, value or other characteristics of + * any distributed ledger nor in respect the functioning or value of any tokens which may + * be created stored or transferred using the Work. The Licensor does not warrant that the + * Work or any use of the Work complies with any law or regulation in any territory where + * it may be implemented or used or that it will be appropriate for any specific purpose. + * + * Neither the licensor nor any current or former employees, officers, directors, partners, + * trustees, representatives, agents, advisors, contractors, or volunteers of the Licensor + * shall be liable for any direct or indirect, special, incidental, consequential or other + * losses of any kind, in tort, contract or otherwise (including but not limited to loss + * of revenue, income or profits, or loss of use or data, or loss of reputation, or loss + * of any economic or other opportunity of whatsoever nature or howsoever arising), arising + * out of or in connection with (without limitation of any use, misuse, of any ledger system + * or use made or its functionality or any performance or operation of any code or protocol + * caused by bugs or programming or logic errors or otherwise); + * + * A. any offer, purchase, holding, use, sale, exchange or transmission of any + * cryptographic keys, tokens or assets created, exchanged, stored or arising from any + * interaction with the Work; + * + * B. any failure in a transmission or loss of any token or assets keys or other digital + * artefacts due to errors in transmission; + * + * C. bugs, hacks, logic errors or faults in the Work or any communication; + * + * D. system software or apparatus including but not limited to losses caused by errors + * in holding or transmitting tokens by any third-party; + * + * E. breaches or failure of security including hacker attacks, loss or disclosure of + * password, loss of private key, unauthorised use or misuse of such passwords or keys; + * + * F. any losses including loss of anticipated savings or other benefits resulting from + * use of the Work or any changes to the Work (however implemented). + * + * You are solely responsible for; testing, validating and evaluation of all operation + * logic, functionality, security and appropriateness of using the Work for any commercial + * or non-commercial purpose and for any reproduction or redistribution by You of the + * Work. You assume all risks associated with Your use of the Work and the exercise of + * permissions under this License. + */ + +using System.Collections.Generic; + +namespace RadixDlt.CoreApiSdk.Model; + +public partial class ConsensusManagerFieldValidatorRewardsValue : IEntityAddressPointer +{ + public IEnumerable GetEntityAddresses() + { + yield return RewardsVault.EntityAddress; + } +} From a191e09f3f6a00e9d0b0c78c77718fdbbe1a2436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20=C5=81abu=C5=9B?= Date: Fri, 28 Jul 2023 14:14:00 +0200 Subject: [PATCH 3/3] Repeat SQL where clause for GetTransactionStream to ensure Postgres query optimizer picks up appropriate index correctly --- .../Services/TransactionQuerier.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/RadixDlt.NetworkGateway.PostgresIntegration/Services/TransactionQuerier.cs b/src/RadixDlt.NetworkGateway.PostgresIntegration/Services/TransactionQuerier.cs index 84e23b563..98bf08509 100644 --- a/src/RadixDlt.NetworkGateway.PostgresIntegration/Services/TransactionQuerier.cs +++ b/src/RadixDlt.NetworkGateway.PostgresIntegration/Services/TransactionQuerier.cs @@ -145,6 +145,7 @@ public async Task GetTransactionStream(TransactionS .Join(_dbContext.LedgerTransactionMarkers, sv => sv, ltm => ltm.StateVersion, (sv, ltm) => ltm) .OfType() .Where(maltm => maltm.OperationType == LedgerTransactionMarkerOperationType.AccountDepositedInto && maltm.EntityId == entityId) + .Where(maltm => maltm.StateVersion <= upperStateVersion && maltm.StateVersion >= (lowerStateVersion ?? maltm.StateVersion)) .Select(maltm => maltm.StateVersion); } } @@ -164,6 +165,7 @@ public async Task GetTransactionStream(TransactionS .Join(_dbContext.LedgerTransactionMarkers, sv => sv, ltm => ltm.StateVersion, (sv, ltm) => ltm) .OfType() .Where(maltm => maltm.OperationType == LedgerTransactionMarkerOperationType.AccountWithdrawnFrom && maltm.EntityId == entityId) + .Where(maltm => maltm.StateVersion <= upperStateVersion && maltm.StateVersion >= (lowerStateVersion ?? maltm.StateVersion)) .Select(maltm => maltm.StateVersion); } } @@ -183,6 +185,7 @@ public async Task GetTransactionStream(TransactionS .Join(_dbContext.LedgerTransactionMarkers, sv => sv, ltm => ltm.StateVersion, (sv, ltm) => ltm) .OfType() .Where(maltm => maltm.OperationType == LedgerTransactionMarkerOperationType.ResourceInUse && maltm.EntityId == entityId) + .Where(maltm => maltm.StateVersion <= upperStateVersion && maltm.StateVersion >= (lowerStateVersion ?? maltm.StateVersion)) .Select(maltm => maltm.StateVersion); } } @@ -200,6 +203,7 @@ public async Task GetTransactionStream(TransactionS .Join(_dbContext.LedgerTransactionMarkers, sv => sv, ltm => ltm.StateVersion, (sv, ltm) => ltm) .OfType() .Where(agetm => agetm.EntityId == entityId) + .Where(agetm => agetm.StateVersion <= upperStateVersion && agetm.StateVersion >= (lowerStateVersion ?? agetm.StateVersion)) .Select(agetm => agetm.StateVersion); } } @@ -244,6 +248,7 @@ public async Task GetTransactionStream(TransactionS .Join(_dbContext.LedgerTransactionMarkers, sv => sv, ltm => ltm.StateVersion, (sv, ltm) => ltm) .OfType() .Where(eltm => eltm.EventType == eventType && eltm.EntityId == (eventEmitterEntityId ?? eltm.EntityId) && eltm.ResourceEntityId == (eventResourceEntityId ?? eltm.ResourceEntityId)) + .Where(eltm => eltm.StateVersion <= upperStateVersion && eltm.StateVersion >= (lowerStateVersion ?? eltm.StateVersion)) .Select(eltm => eltm.StateVersion); } } @@ -269,6 +274,7 @@ public async Task GetTransactionStream(TransactionS .Join(_dbContext.LedgerTransactionMarkers, sv => sv, ltm => ltm.StateVersion, (sv, ltm) => ltm) .OfType() .Where(oltm => oltm.OriginType == originType) + .Where(oltm => oltm.StateVersion <= upperStateVersion && oltm.StateVersion >= (lowerStateVersion ?? oltm.StateVersion)) .Select(oltm => oltm.StateVersion); }