Skip to content

Commit

Permalink
chore(migration): final migration scripts for oct-2 ant fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Oct 2, 2024
1 parent 43342c0 commit 4891a92
Show file tree
Hide file tree
Showing 9 changed files with 706 additions and 159 deletions.
12 changes: 7 additions & 5 deletions tools/aos-bundled.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ function ant.init()
Logo = Logo,
Denomination = tostring(Denomination),
Owner = Owner,
HandlerNames = utils.getHandlerNames(Handlers),
Handlers = utils.getHandlerNames(Handlers),
["Source-Code-TX-ID"] = SourceCodeTxId,
}
ao.send({
Expand Down Expand Up @@ -1235,7 +1235,7 @@ function ant.init()
end
local tags = msg.Tags
local name, transactionId, ttlSeconds =
tags["Sub-Domain"], tags["Transaction-Id"], tonumber(tags["TTL-Seconds"])
string.lower(tags["Sub-Domain"]), tags["Transaction-Id"], tonumber(tags["TTL-Seconds"])

local setRecordStatus, setRecordResult = pcall(records.setRecord, name, transactionId, ttlSeconds)
if not setRecordStatus then
Expand All @@ -1257,7 +1257,8 @@ function ant.init()
if assertHasPermission == false then
return ao.send({ Target = msg.From, Action = "Invalid-Remove-Record-Notice", Data = permissionErr })
end
local removeRecordStatus, removeRecordResult = pcall(records.removeRecord, msg.Tags["Sub-Domain"])
local name = string.lower(msg.Tags["Sub-Domain"])
local removeRecordStatus, removeRecordResult = pcall(records.removeRecord, name)
if not removeRecordStatus then
ao.send({
Target = msg.From,
Expand All @@ -1272,7 +1273,8 @@ function ant.init()
end)

Handlers.add(camel(ActionMap.Record), utils.hasMatchingTag("Action", ActionMap.Record), function(msg)
local nameStatus, nameRes = pcall(records.getRecord, msg.Tags["Sub-Domain"])
local name = string.lower(msg.Tags["Sub-Domain"])
local nameStatus, nameRes = pcall(records.getRecord, name)
if not nameStatus then
ao.send({
Target = msg.From,
Expand All @@ -1287,7 +1289,7 @@ function ant.init()
local recordNotice = {
Target = msg.From,
Action = "Record-Notice",
Name = msg.Tags["Sub-Domain"],
Name = name,
Data = nameRes,
}

Expand Down
36 changes: 23 additions & 13 deletions tools/create-csv-from-arns-records.mjs
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
import { AOProcess, IO, IO_DEVNET_PROCESS_ID, IO_TESTNET_PROCESS_ID } from '@ar.io/sdk';
import { connect } from '@permaweb/aoconnect';
import path from 'path';
import fs from 'fs';
import {
AOProcess,
IO,
IO_DEVNET_PROCESS_ID,
IO_TESTNET_PROCESS_ID,
} from "@ar.io/sdk";
import { connect } from "@permaweb/aoconnect";
import path from "path";
import fs from "fs";

const __dirname = path.dirname(new URL(import.meta.url).pathname);
const restart = process.argv.includes('--restart');
const testnet = process.argv.includes('--testnet');
const restart = process.argv.includes("--restart");
const testnet = process.argv.includes("--testnet");
async function main() {
const io = IO.init({
process: new AOProcess({
processId: testnet ? IO_TESTNET_PROCESS_ID : IO_DEVNET_PROCESS_ID,
ao: connect({
CU_URL: 'https://cu.ar-io.dev',
CU_URL: "https://cu.ar-io.dev",
}),
}),
});

const outputFilePath = path.join(__dirname, `arns-processid-mapping-${testnet ? 'testnet' : 'devnet'}.csv`);
const outputFilePath = path.join(
__dirname,
`arns-processid-mapping-${testnet ? "testnet" : "devnet"}.csv`,
);

const arnsRecords = await io.getArNSRecords({
limit: 100000,
sortBy: 'startTimestamp',
sortOrder: 'asc',
sortBy: "startTimestamp",
sortOrder: "asc",
});

// recreate the file if restart is true
if (!fs.existsSync(outputFilePath) || restart) {
fs.writeFileSync(outputFilePath, 'domain,oldProcessId\n', { flag: 'w' });
fs.writeFileSync(outputFilePath, "domain,oldProcessId\n", { flag: "w" });
}

console.log(`Found ${arnsRecords.items.length} ARNS records for process, mapping to CSV for processing`);
console.log(
`Found ${arnsRecords.items.length} ARNS records for process, mapping to CSV for processing`,
);
arnsRecords.items.forEach((record) => {
fs.writeFileSync(outputFilePath, `${record.name},${record.processId}\n`, {
flag: 'a',
flag: "a",
});
});
console.log(`Wrote ${arnsRecords.items.length} ARNS records to CSV`);
Expand Down
85 changes: 85 additions & 0 deletions tools/deduplicate-ant-new-process-ids.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import Arweave from "arweave";
import path from "path";
import fs from "fs";

const __dirname = path.dirname(new URL(import.meta.url).pathname);
const restart = process.argv.includes("--restart");
const inputFilePath = process.argv.includes("--file")
? process.argv[process.argv.indexOf("--file") + 1]
: null;
const wallet = JSON.parse(
fs.readFileSync(path.join(__dirname, "key.json"), "utf8"),
);
const testnet = process.argv.includes("--testnet");
const arweave = Arweave.init({
host: "arweave.net",
port: 443,
protocol: "https",
});
const index = process.argv.includes("--index")
? process.argv[process.argv.indexOf("--index") + 1]
: null;

async function main() {
const csv = fs.readFileSync(path.join(__dirname, inputFilePath), "utf8");

const postfix = index ? `-${index}` : "";

const outputFilePath = path.join(
__dirname,
`deduplicated-processids-${testnet ? "testnet" : "devnet"}${postfix}.csv`,
);

// print out address of wallet being used
const address = await arweave.wallets.jwkToAddress(wallet);
console.log(`Using wallet ${address} to evaluate ants`);

const alreadyCreatedProcessIds = csv
.split("\n")
.slice(1) // skip header
.map((line) => line.split(","))
.filter(
([domain, oldProcessId, newProcessId]) =>
domain && oldProcessId && newProcessId && oldProcessId !== newProcessId,
);

// create output csv if not exists including eval result
if (!fs.existsSync(outputFilePath) || restart) {
fs.writeFileSync(outputFilePath, "domain,oldProcessId,newProcessId\n", {
flag: "w",
});
}

const processMap = new Map();

// process map - don't re-evaluate ants that have already been evaluated

for (const [domain, oldProcessId, newProcessId] of alreadyCreatedProcessIds) {
console.log(`Evaluating ant ${newProcessId}`);

// don't eval if we already have on the process map
if (processMap.has(oldProcessId)) {
console.log(`Skipping ${oldProcessId} as it has already been created`);
fs.writeFileSync(
outputFilePath,
`${domain},${oldProcessId},${processMap.get(oldProcessId)}\n`,
{
flag: "a",
},
);
continue;
}

fs.writeFileSync(
outputFilePath,
`${domain},${oldProcessId},${newProcessId}\n`,
{
flag: "a",
},
);

processMap.set(oldProcessId, newProcessId);
}
}

main();
Empty file.
Loading

0 comments on commit 4891a92

Please sign in to comment.