Fixing Lease amount update in mismatches (#369)

This commit is contained in:
Kithmini Gunawardhana
2024-03-01 19:06:07 +05:30
committed by GitHub
parent 3199d2d559
commit 324300058a
2 changed files with 9 additions and 15 deletions

View File

@@ -128,16 +128,12 @@ class MessageBoard {
const diskMb = Math.floor(sashiConfig.system.max_storage_kbytes / 1000);
const cpuMicroSec = sashiConfig.system.max_cpu_us;
const totalInstanceCount = sashiConfig.system.max_instance_count;
// Allows to update the lease price if the figure deviates from the figure in host registration entry AND
// * All the leases are acquired OR
// * The price of an unsold lease is equal to the value in the configuration.
const availableLeases = await this.hostClient.getLeases();
const allowLeaseAmountUpdate = ((parseFloat(hostInfo.leaseAmount) !== this.cfg.xrpl.leaseAmount) &&
(availableLeases.length === 0 || Number(availableLeases[0].Amount?.value) === this.cfg.xrpl.leaseAmount))
if ((parseFloat(hostInfo.leaseAmount) !== this.cfg.xrpl.leaseAmount) && !allowLeaseAmountUpdate) {
const availableLeaseOffers = await this.hostClient.getLeaseOffers();
if (availableLeaseOffers.length > 0 && (Number(availableLeaseOffers[0].Amount?.value) !== this.cfg.xrpl.leaseAmount)) {
console.log("Lease amount inconsistency was found with existing leases.");
console.log(`Using previous lease amount as ${hostInfo.leaseAmount} EVRs.`);
this.cfg.xrpl.leaseAmount = parseFloat(hostInfo.leaseAmount);
console.log(`Using previous lease amount as ${Number(availableLeaseOffers[0].Amount?.value)} EVRs.`);
this.cfg.xrpl.leaseAmount = parseFloat(availableLeaseOffers[0].Amount?.value);
this.persistConfig();
}
@@ -148,7 +144,7 @@ class MessageBoard {
hostInfo.cpuMicrosec === cpuMicroSec &&
hostInfo.ramMb === ramMb &&
hostInfo.diskMb === diskMb &&
!allowLeaseAmountUpdate)) {
hostInfo.leaseAmount === this.cfg.xrpl.leaseAmount)) {
await this.#queueAction(async (submissionRefs) => {
submissionRefs.refs ??= [{}];
// Check again wether the transaction is validated before retry.

View File

@@ -573,11 +573,9 @@ class Setup {
});
const hostInfo = await hostClient.getHostInfo();
const availableLeases = await hostClient.getLeases();
const allowLeaseAmountUpdate = ((parseFloat(hostInfo.leaseAmount) !== cfg.xrpl.leaseAmount) &&
(availableLeases.length === 0 || Number(availableLeases[0].Amount?.value) === acc.leaseAmount))
if (!allowLeaseAmountUpdate) {
acc.leaseAmount = parseFloat(hostInfo.leaseAmount);
const availableLeaseOffers = await hostClient.getLeaseOffers();
if (availableLeaseOffers.length > 0 && Number(availableLeaseOffers[0].Amount?.value) !== acc.leaseAmount) {
acc.leaseAmount = parseFloat(availableLeaseOffers[0].Amount?.value);
}
await hostClient.updateRegInfo(hostInfo.activeInstances, null, null, null, null, null, null, null, null, emailAddress, acc?.leaseAmount, { retryOptions: { maxRetryAttempts: MAX_TX_RETRY_ATTEMPTS, feeUplift: Math.floor(acc.affordableExtraFee / MAX_TX_RETRY_ATTEMPTS) } });