Skip to content

Commit

Permalink
fix(scripts): update migration scripts to reset gateway stats
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed May 29, 2024
1 parent 23d3807 commit 72204aa
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 7 deletions.
13 changes: 13 additions & 0 deletions contract/src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,17 @@ Handlers.add('addGateway', utils.hasMatchingTag("Action", 'AddGateway'), functio
end
end)

Handlers.add('addRecord', utils.hasMatchingTag("Action", 'AddRecord'), function(msg)
if(msg.From ~= Owner) then
ao.send({ Target = msg.From, Data = "Unauthorized" })
return
end
local status, result = pcall(arns.addRecord, msg.Tags.Name, json.decode(msg.Data))
if status then
ao.send({ Target = msg.From, Data = json.encode(result) })
else
ao.send({ Target = msg.From, Data = json.encode(result) })
end
end)

return process
12 changes: 5 additions & 7 deletions migration/migrate-gateways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const main = async () => {
});
const currentBlock = await arweave.blocks.getCurrent();
const millisecondsPerBlock = 1000 * 2 * 60; // two minutes

for (const [address, gateway] of Object.entries(gateways)) {
const { message, result } = await connect(jwk)
const startTimestamp = await arweave.blocks.getByHeight(gateway.start).then(block => block.timestamp)
Expand All @@ -42,19 +41,18 @@ const main = async () => {
observerAddress: gateway.observerWallet,
operatorStake: gateway.operatorStake,
settings: gateway.settings,
// TODO: fetch the block height of the gateway block height
startTimestamp: startTimestamp,
status: gateway.status,
stats: {
...gateway.stats,
// give them the max amount of passed
"passedConsecutiveEpochs": gateway.stats.passedEpochCount,
passedEpochCount: 0,
submittedObservationEpochCount: 0,
prescribedEpochCount: 0,
failedConsecutiveEpochs: 0,
passedConsecutiveEpochs: 0,
},
// TODO: fetch the block height of the gateway block height
endTimestamp: endTimestamp,
delegates: gateway.delegates,
vaults: gateway.vaults,

}),
signer: createDataItemSigner(jwk),
});
Expand Down
72 changes: 72 additions & 0 deletions migration/migrate-records.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
createDataItemSigner,
connect,
} from "@permaweb/aoconnect";
import { ArIO } from "@ar.io/sdk";
import Arweave from 'arweave'

import fs from 'fs'
import path from 'path'

const processId = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc'
const dirname = new URL(import.meta.url).pathname
const jwk = JSON.parse(fs.readFileSync(path.join(dirname, '../wallet.json')).toString())
// const scheduler = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA' // tom's scheduler
const main = async () => {
// fetch gateways from contract
const devnetContract = ArIO.init({
contractTxId: '_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8'
})
const records = await devnetContract.getArNSRecords();
const arweave = Arweave.init({
host: 'arweave.net',
port: 443,
protocol: 'https',
});
// const uniqueSetOfContractTxIds = new Set(Object.values(records).map(record => record.contractTxId))
// const mapOfContractTxIdToAntTxId: Record<string, string> = {}
// spawn ANT using ANT module (or inject source code) for each contract
// for (const contractTxId of uniqueSetOfContractTxIds) {
// const processId = await spawn({
// // The Arweave TXID of the ao Module
// module: '', // TODO: replace with the actual module tx id
// scheduler: scheduler,
// tags: [
// { name: "Memory-Limit", value: "500-mb" },
// { name: "Compute-Limit", value: "9000000000000" },
// { name: "ContractTxId", value: contractTxId}
// ],
// // A signer function containing your wallet
// signer: createDataItemSigner(jwk),
// });
// mapOfContractTxIdToAntTxId[contractTxId] = processId
// }
const currentBlock = await arweave.blocks.getCurrent();
for (const [name, record] of Object.entries(records)) {
const { message, result } = await connect(jwk)
const messageTxId = await message({
process: processId,
tags: [
{ name: 'ProcessId', value: processId},
{ name: 'Action', value: 'AddRecord' },
{ name: 'Name', value: name},
],
data: JSON.stringify({
type: 'lease',
endTimestamp: currentBlock.timestamp * (1000 * 60 * 60 * 24 * 365 * 2), // 2 years
contractTxId: record.contractTxId,
undernameLimit: record.undernames,
purchasePrice: record.purchasePrice,
}),
signer: createDataItemSigner(jwk),
});
console.log('Sent data to process', messageTxId)
const res = await result({
message: messageTxId,
process: processId
})
console.log('Result:', res)
}
}

main()

0 comments on commit 72204aa

Please sign in to comment.