From 0b7ebbec91aaaa06cfbf98158be5e89293482986 Mon Sep 17 00:00:00 2001 From: vilenarios Date: Tue, 25 Jun 2024 17:10:25 -0400 Subject: [PATCH 1/9] Adds TTLs for getting records --- scripts/arns-resolver.lua | 55 +++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/scripts/arns-resolver.lua b/scripts/arns-resolver.lua index a270f04f..eb78f38d 100644 --- a/scripts/arns-resolver.lua +++ b/scripts/arns-resolver.lua @@ -2,9 +2,11 @@ local json = require("json") -- Constants -- Used to determine when to require name resolution -ID_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default -DATA_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default -OWNER_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default +REGISTRY_TTL_MS = 7 * 24 * 60 * 60 * 1000 -- 7 days hours by default +REGISTRATION_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default +PROCESS_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default +DATA_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default +OWNER_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default -- Process IDs for interacting with other services or processes AR_IO_DEVNET_PROCESS_ID = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc" @@ -58,6 +60,12 @@ local arnsMeta = { name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) if NAMES[rootName] == nil then + if PROCESSES[NAMES[rootName].processId] == nil then + PROCESSES[NAMES[name].processId] = { + Names = {} + } + end + PROCESSES[NAMES[name].processId].Names[name] = true ao.send({ Target = PROCESS_ID, Action = "Record", Name = rootName }) print(name .. " has not been resolved yet. Resolving now...") return nil @@ -92,6 +100,12 @@ local arnsMeta = { name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) if NAMES[rootName] == nil then + if PROCESSES[NAMES[rootName].processId] == nil then + PROCESSES[NAMES[name].processId] = { + Names = {} + } + end + PROCESSES[NAMES[name].processId].Names[name] = true ao.send({ Target = PROCESS_ID, Action = "Record", Name = rootName }) print(name .. " has not been resolved yet. Cannot get owner. Resolving now...") return nil @@ -113,10 +127,16 @@ local arnsMeta = { name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) if NAMES[rootName] == nil then + if PROCESSES[NAMES[rootName].processId] == nil then + PROCESSES[NAMES[name].processId] = { + Names = {} + } + end + PROCESSES[NAMES[name].processId].Names[name] = true ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) print(name .. " has not been resolved yet. Cannot get process id. Resolving now...") return nil - elseif Now - NAMES[rootName].lastUpdated >= ID_TTL_MS then + elseif Now - NAMES[rootName].lastUpdated >= REGISTRATION_TTL_MS then ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) print(name .. " is stale. Refreshing name data now...") return nil @@ -128,11 +148,17 @@ local arnsMeta = { return function(name) name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) - if NAMES[rootName] == nil and PROCESSES[NAMES[rootName].processId].state == nil then + if NAMES[rootName] == nil then + if PROCESSES[NAMES[rootName].processId] == nil then + PROCESSES[NAMES[name].processId] = { + Names = {} + } + end + PROCESSES[NAMES[name].processId].Names[name] = true ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) print(name .. " has not been resolved yet. Cannot get process id. Resolving now...") return nil - elseif Now - NAMES[rootName].lastUpdated >= ID_TTL_MS or Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= ID_TTL_MS then + elseif Now - NAMES[rootName].lastUpdated >= REGISTRATION_TTL_MS or Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= PROCESS_TTL_MS then ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) print(name .. " is stale. Refreshing name data now...") return nil @@ -145,7 +171,7 @@ local arnsMeta = { end elseif key == "records" then return function() - if NAMES == nil or PROCESSES == nil then + if NAMES == {} or PROCESSES == {} then ao.send({ Target = PROCESS_ID, Action = "Records" }) print("ArNS Records have not been resolved yet... Resolving now...") return nil @@ -165,12 +191,12 @@ local arnsMeta = { NAMES = {} ACL = {} PROCESSES = {} - return "ArNS local name cache cleared." + return "ArNS local cache cleared." end elseif key == "resolveAll" then return function() ao.send({ Target = PROCESS_ID, Action = "Records" }) - return "Getting entire ArNS registry" + return "Looking up and resolving all ArNS Records" end elseif key == "count" then return function() @@ -264,6 +290,7 @@ Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg if record.endTimestamp ~= nil then NAMES[name].endTimestamp = record.endTimestamp end + if NAMES[name].processId then print('Resolving ' .. name .. ' to ANT: ' .. NAMES[name].processId) namesFetched = namesFetched + 1 @@ -278,8 +305,14 @@ Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg end end for processId, process in pairs(PROCESSES) do - ao.send({ Target = processId, Action = "State" }) - antsResolved = antsResolved + 1 + if PROCESSES[processId].state and PROCESSES[processId].state.lastUpdated and Now - PROCESSES[processId].state.lastUpdated < REGISTRY_TTL_MS then + print('TTL has not expired yet for ' .. processId) + else + print('Updating state for ' .. processId) + print(PROCESSES[processId]) + ao.send({ Target = processId, Action = "State" }) + antsResolved = antsResolved + 1 + end end end print("Updated " .. antsResolved .. " ANTs across " .. namesFetched .. " names with the latest ArNS Registry info!") From 09695364069898eafa9fc0967ff6640c5b4ed3b8 Mon Sep 17 00:00:00 2001 From: vilenarios Date: Tue, 25 Jun 2024 17:51:35 -0400 Subject: [PATCH 2/9] chore: sets process id to use ar.io testnet --- scripts/arns-resolver.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/arns-resolver.lua b/scripts/arns-resolver.lua index eb78f38d..fee8c55c 100644 --- a/scripts/arns-resolver.lua +++ b/scripts/arns-resolver.lua @@ -11,7 +11,7 @@ OWNER_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default -- Process IDs for interacting with other services or processes AR_IO_DEVNET_PROCESS_ID = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc" AR_IO_TESTNET_PROCESS_ID = "agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA" -PROCESS_ID = PROCESS_ID or AR_IO_DEVNET_PROCESS_ID +PROCESS_ID = PROCESS_ID or AR_IO_TESTNET_PROCESS_ID -- Initialize the NAMES and ID_NAME_MAPPING tables NAMES = NAMES or {} From 5ea275588863bd9b0b6621ba0cf43ded580ecc5f Mon Sep 17 00:00:00 2001 From: vilenarios Date: Tue, 25 Jun 2024 18:19:08 -0400 Subject: [PATCH 3/9] chore: makes variable names clearer --- scripts/arns-resolver.lua | 59 ++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/scripts/arns-resolver.lua b/scripts/arns-resolver.lua index fee8c55c..d1b17dee 100644 --- a/scripts/arns-resolver.lua +++ b/scripts/arns-resolver.lua @@ -2,16 +2,16 @@ local json = require("json") -- Constants -- Used to determine when to require name resolution -REGISTRY_TTL_MS = 7 * 24 * 60 * 60 * 1000 -- 7 days hours by default -REGISTRATION_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default -PROCESS_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default -DATA_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default -OWNER_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default +ARNS_TTL_MS = 7 * 24 * 60 * 60 * 1000 -- 7 days hours by default +ARNS_RECORD_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default +ANT_PROCESS_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default +ANT_DATA_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default +ANT_OWNER_TTL_MS = 24 * 60 * 60 * 1000 -- 24 hours by default -- Process IDs for interacting with other services or processes AR_IO_DEVNET_PROCESS_ID = "GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc" AR_IO_TESTNET_PROCESS_ID = "agYcCFJtrMG6cqMuZfskIkFTGvUPddICmtQSBIoPdiA" -PROCESS_ID = PROCESS_ID or AR_IO_TESTNET_PROCESS_ID +AR_IO_PROCESS_ID = AR_IO_PROCESS_ID or AR_IO_TESTNET_PROCESS_ID -- Initialize the NAMES and ID_NAME_MAPPING tables NAMES = NAMES or {} @@ -52,7 +52,7 @@ local arnsMeta = { if key == "resolve" then return function(name) name = string.lower(name) - ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) return "Getting information for name: " .. name end elseif key == "data" then @@ -66,13 +66,13 @@ local arnsMeta = { } end PROCESSES[NAMES[name].processId].Names[name] = true - ao.send({ Target = PROCESS_ID, Action = "Record", Name = rootName }) + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) print(name .. " has not been resolved yet. Resolving now...") return nil elseif rootName and underName == nil then if PROCESSES[NAMES[rootName].processId] and (PROCESSES[NAMES[rootName].processId].state.Records["@"] or PROCESSES[NAMES[rootName].processId].state.records["@"]) then - if Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= DATA_TTL_MS then - ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) + if Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= ANT_DATA_TTL_MS then + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) print(name .. " is stale. Refreshing name process now...") return nil else @@ -82,8 +82,8 @@ local arnsMeta = { end elseif rootName and underName then if PROCESSES[NAMES[rootName].processId] and (PROCESSES[NAMES[rootName].processId].state.Records[underName] or PROCESSES[NAMES[rootName].processId].state.records[underName]) then - if Now - PROCESSES[NAMES[rootName].processId].lastUpdated >= DATA_TTL_MS then - ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) + if Now - PROCESSES[NAMES[rootName].processId].lastUpdated >= ANT_DATA_TTL_MS then + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) print(name .. " is stale. Refreshing name process now...") return nil else @@ -106,12 +106,12 @@ local arnsMeta = { } end PROCESSES[NAMES[name].processId].Names[name] = true - ao.send({ Target = PROCESS_ID, Action = "Record", Name = rootName }) + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) print(name .. " has not been resolved yet. Cannot get owner. Resolving now...") return nil elseif PROCESSES[NAMES[rootName].processId] and (PROCESSES[NAMES[rootName].processId].state.Owner or PROCESSES[NAMES[rootName].processId].state.owner) then - if Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= OWNER_TTL_MS then - ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) + if Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= ANT_OWNER_TTL_MS then + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) print(name .. " is stale. Refreshing name process now...") return nil else @@ -133,11 +133,11 @@ local arnsMeta = { } end PROCESSES[NAMES[name].processId].Names[name] = true - ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) print(name .. " has not been resolved yet. Cannot get process id. Resolving now...") return nil - elseif Now - NAMES[rootName].lastUpdated >= REGISTRATION_TTL_MS then - ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) + elseif Now - NAMES[rootName].lastUpdated >= ARNS_RECORD_TTL_MS then + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) print(name .. " is stale. Refreshing name data now...") return nil else @@ -155,11 +155,11 @@ local arnsMeta = { } end PROCESSES[NAMES[name].processId].Names[name] = true - ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) print(name .. " has not been resolved yet. Cannot get process id. Resolving now...") return nil - elseif Now - NAMES[rootName].lastUpdated >= REGISTRATION_TTL_MS or Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= PROCESS_TTL_MS then - ao.send({ Target = PROCESS_ID, Action = "Record", Name = name }) + elseif Now - NAMES[rootName].lastUpdated >= ARNS_RECORD_TTL_MS or Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= ANT_PROCESS_TTL_MS then + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) print(name .. " is stale. Refreshing name data now...") return nil else @@ -172,8 +172,10 @@ local arnsMeta = { elseif key == "records" then return function() if NAMES == {} or PROCESSES == {} then - ao.send({ Target = PROCESS_ID, Action = "Records" }) - print("ArNS Records have not been resolved yet... Resolving now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Records" }) + print("ArNS Records have not been resolved yet...") + print("Looking up and resolving all Records from ArNS Registry: " .. AR_IO_PROCESS_ID) + return nil else local records = {} @@ -195,8 +197,8 @@ local arnsMeta = { end elseif key == "resolveAll" then return function() - ao.send({ Target = PROCESS_ID, Action = "Records" }) - return "Looking up and resolving all ArNS Records" + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Records" }) + return "Looking up and resolving all Records ArNS Registry: " .. AR_IO_PROCESS_ID end elseif key == "count" then return function() @@ -214,7 +216,7 @@ ARNS = setmetatable({}, arnsMeta) -- @param msg The message to evaluate. -- @return boolean True if the message is from the ARNS process and action is 'Record-Resolved', otherwise false. function isArNSGetRecordMessage(msg) - if msg.From == PROCESS_ID and (msg.Tags.Action == 'Record-Notice' or msg.Tags.Action == 'Records-Notice') then + if msg.From == AR_IO_PROCESS_ID and (msg.Tags.Action == 'Record-Notice' or msg.Tags.Action == 'Records-Notice') then return true else return false @@ -243,7 +245,6 @@ end) -- Updates or initializes the record for the given name with the latest information. -- Fetches additional information from SmartWeave Cache or ANT-AO process if necessary. Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg) - print("Received message from ArNS Registry") local data, err = json.decode(msg.Data) if not data or err then print("Error decoding JSON data: ", err) @@ -305,7 +306,7 @@ Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg end end for processId, process in pairs(PROCESSES) do - if PROCESSES[processId].state and PROCESSES[processId].state.lastUpdated and Now - PROCESSES[processId].state.lastUpdated < REGISTRY_TTL_MS then + if PROCESSES[processId].state and PROCESSES[processId].state.lastUpdated and Now - PROCESSES[processId].state.lastUpdated < ARNS_TTL_MS then print('TTL has not expired yet for ' .. processId) else print('Updating state for ' .. processId) @@ -315,7 +316,7 @@ Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg end end end - print("Updated " .. antsResolved .. " ANTs across " .. namesFetched .. " names with the latest ArNS Registry info!") + print("Updated " .. antsResolved .. " ANTs across " .. namesFetched .. " Records") end) --- Updates stored information with the latest data from ANT-AO process "Info-Notice" messages. From 798a437504f8defa2692cc73b2d6a1fb9b37eebc Mon Sep 17 00:00:00 2001 From: vilenarios Date: Wed, 26 Jun 2024 11:50:56 -0400 Subject: [PATCH 4/9] fixes errors in the metatable --- scripts/arns-resolver.lua | 133 +++++++++++++++++++++++--------------- 1 file changed, 82 insertions(+), 51 deletions(-) diff --git a/scripts/arns-resolver.lua b/scripts/arns-resolver.lua index d1b17dee..a1836fac 100644 --- a/scripts/arns-resolver.lua +++ b/scripts/arns-resolver.lua @@ -47,33 +47,52 @@ function countTableItems(tbl) return count end +function countResolvedNames() + local count = 0 + for name, record in pairs(NAMES) do + if PROCESSES[NAMES[name].processId] and PROCESSES[NAMES[name].processId].state then + count = count + 1 + end + end + return count +end + +function countResolvedProcesses() + local count = 0 + for process, record in pairs(PROCESSES) do + if process.state then + count = count + 1 + end + end + return count +end + local arnsMeta = { __index = function(t, key) if key == "resolve" then return function(name) name = string.lower(name) - ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) - return "Getting information for name: " .. name + local rootName, underName = splitIntoTwoNames(name) + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) + return "Getting information for name: " .. rootName end elseif key == "data" then return function(name) name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) if NAMES[rootName] == nil then - if PROCESSES[NAMES[rootName].processId] == nil then - PROCESSES[NAMES[name].processId] = { - Names = {} - } - end - PROCESSES[NAMES[name].processId].Names[name] = true + print("Cannot get data for name " .. + rootName .. ", it has not been looked up and resolved yet. Resolving now...") ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) - print(name .. " has not been resolved yet. Resolving now...") return nil + elseif PROCESSES[NAMES[rootName].processId].state == nil then + print("Cannot get data for name " .. name .. ", it has not been resolved yet. Resolving now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) elseif rootName and underName == nil then if PROCESSES[NAMES[rootName].processId] and (PROCESSES[NAMES[rootName].processId].state.Records["@"] or PROCESSES[NAMES[rootName].processId].state.records["@"]) then if Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= ANT_DATA_TTL_MS then - ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) print(name .. " is stale. Refreshing name process now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) return nil else return PROCESSES[NAMES[rootName].processId].state.Records["@"].transactionId or @@ -81,14 +100,19 @@ local arnsMeta = { end end elseif rootName and underName then - if PROCESSES[NAMES[rootName].processId] and (PROCESSES[NAMES[rootName].processId].state.Records[underName] or PROCESSES[NAMES[rootName].processId].state.records[underName]) then - if Now - PROCESSES[NAMES[rootName].processId].lastUpdated >= ANT_DATA_TTL_MS then - ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) - print(name .. " is stale. Refreshing name process now...") - return nil + if PROCESSES[NAMES[rootName].processId] then + if PROCESSES[NAMES[rootName].processId].state.Records[underName] ~= nil then + if Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= ANT_DATA_TTL_MS then + print(name .. " is stale. Refreshing name process now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) + return nil + else + return PROCESSES[NAMES[rootName].processId].state.Records[underName].transactionId or + PROCESSES[NAMES[rootName].processId].state.records[underName].transactionId + end else - return PROCESSES[NAMES[rootName].processId].Records[underName].transactionId or - PROCESSES[NAMES[rootName].processId].records[underName].transactionId + print(underName .. ' is not a valid undername in the name ' .. rootName) + return nil end else return nil @@ -100,19 +124,17 @@ local arnsMeta = { name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) if NAMES[rootName] == nil then - if PROCESSES[NAMES[rootName].processId] == nil then - PROCESSES[NAMES[name].processId] = { - Names = {} - } - end - PROCESSES[NAMES[name].processId].Names[name] = true + print("Cannot get owner for name " .. + rootName .. ", it has not been looked up and resolved yet. Resolving now...") ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) - print(name .. " has not been resolved yet. Cannot get owner. Resolving now...") return nil + elseif PROCESSES[NAMES[rootName].processId].state == nil then + print("Cannot get owner for name " .. rootName .. ", it has not been resolved yet. Resolving now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) elseif PROCESSES[NAMES[rootName].processId] and (PROCESSES[NAMES[rootName].processId].state.Owner or PROCESSES[NAMES[rootName].processId].state.owner) then if Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= ANT_OWNER_TTL_MS then - ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) print(name .. " is stale. Refreshing name process now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) return nil else return PROCESSES[NAMES[rootName].processId].state.Owner or @@ -127,18 +149,19 @@ local arnsMeta = { name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) if NAMES[rootName] == nil then + print("Cannot get process id for name " .. + rootName .. ", it has not been looked up and resolved yet. Resolving now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) + return nil + elseif Now - NAMES[rootName].lastUpdated >= ARNS_RECORD_TTL_MS then if PROCESSES[NAMES[rootName].processId] == nil then - PROCESSES[NAMES[name].processId] = { + PROCESSES[NAMES[rootName].processId] = { Names = {} } + PROCESSES[NAMES[rootName].processId].Names[name] = true end - PROCESSES[NAMES[name].processId].Names[name] = true - ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) - print(name .. " has not been resolved yet. Cannot get process id. Resolving now...") - return nil - elseif Now - NAMES[rootName].lastUpdated >= ARNS_RECORD_TTL_MS then - ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) - print(name .. " is stale. Refreshing name data now...") + print(rootName .. " is stale. Refreshing name data now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) return nil else return NAMES[rootName].processId or nil @@ -149,18 +172,13 @@ local arnsMeta = { name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) if NAMES[rootName] == nil then - if PROCESSES[NAMES[rootName].processId] == nil then - PROCESSES[NAMES[name].processId] = { - Names = {} - } - end - PROCESSES[NAMES[name].processId].Names[name] = true - ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) - print(name .. " has not been resolved yet. Cannot get process id. Resolving now...") + print("Cannot get process id for name " .. + rootName .. ", it has not been looked up and resolved yet. Resolving now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) return nil elseif Now - NAMES[rootName].lastUpdated >= ARNS_RECORD_TTL_MS or Now - PROCESSES[NAMES[rootName].processId].state.lastUpdated >= ANT_PROCESS_TTL_MS then - ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = name }) - print(name .. " is stale. Refreshing name data now...") + print(rootName .. " is stale. Refreshing name data now...") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) return nil else local record = NAMES[rootName] @@ -172,10 +190,10 @@ local arnsMeta = { elseif key == "records" then return function() if NAMES == {} or PROCESSES == {} then - ao.send({ Target = AR_IO_PROCESS_ID, Action = "Records" }) print("ArNS Records have not been resolved yet...") - print("Looking up and resolving all Records from ArNS Registry: " .. AR_IO_PROCESS_ID) - + print("Looking up and resolving all Records from ArNS Registry: " .. + AR_IO_PROCESS_ID .. "...this may take a while!") + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Records" }) return nil else local records = {} @@ -198,11 +216,25 @@ local arnsMeta = { elseif key == "resolveAll" then return function() ao.send({ Target = AR_IO_PROCESS_ID, Action = "Records" }) - return "Looking up and resolving all Records ArNS Registry: " .. AR_IO_PROCESS_ID + return "Looking up and resolving all Records from ArNS Registry: " .. + AR_IO_PROCESS_ID .. "...this may take a while!" end elseif key == "count" then - return function() - return countTableItems(NAMES) + return function(type) + type = string.lower(type) + if type == 'names' then + return countResolvedNames() + elseif type == 'processes' then + return countResolvedProcesses() + elseif type == 'acl' then + return countTableItems(ACL) + elseif type == 'unresolvednames' then + return countTableItems(NAMES) + elseif type == 'unresolvedprocesses' then + return countTableItems(PROCESSES) + else + return 'Invalid type entered. Can only count names, processes and acl.' + end end else return nil @@ -247,7 +279,7 @@ end) Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg) local data, err = json.decode(msg.Data) if not data or err then - print("Error decoding JSON data: ", err) + print("Error decoding JSON data from ArNS Registry: ", err) return end local namesFetched = 0 @@ -310,7 +342,6 @@ Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg print('TTL has not expired yet for ' .. processId) else print('Updating state for ' .. processId) - print(PROCESSES[processId]) ao.send({ Target = processId, Action = "State" }) antsResolved = antsResolved + 1 end From 75a557e308c18af184116a38377be65b1d5e93b3 Mon Sep 17 00:00:00 2001 From: vilenarios Date: Thu, 27 Jun 2024 07:37:07 -0400 Subject: [PATCH 5/9] wip --- scripts/arns-resolver.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/arns-resolver.lua b/scripts/arns-resolver.lua index a1836fac..87a599fa 100644 --- a/scripts/arns-resolver.lua +++ b/scripts/arns-resolver.lua @@ -59,7 +59,7 @@ end function countResolvedProcesses() local count = 0 - for process, record in pairs(PROCESSES) do + for processId, process in pairs(PROCESSES) do if process.state then count = count + 1 end @@ -229,11 +229,13 @@ local arnsMeta = { elseif type == 'acl' then return countTableItems(ACL) elseif type == 'unresolvednames' then - return countTableItems(NAMES) + local unresolvedNames = countTableItems(NAMES) - countResolvedNames() + return unresolvedNames elseif type == 'unresolvedprocesses' then - return countTableItems(PROCESSES) + local unresolvedProcesses = countTableItems(PROCESSES) - countResolvedProcesses() + return unresolvedProcesses else - return 'Invalid type entered. Can only count names, processes and acl.' + return 'Invalid type entered. Can only count names, processes, acl, unresolvednames and unresolvedprocesses.' end end else @@ -325,7 +327,7 @@ Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg end if NAMES[name].processId then - print('Resolving ' .. name .. ' to ANT: ' .. NAMES[name].processId) + -- print('Resolving ' .. name .. ' to ANT: ' .. NAMES[name].processId) namesFetched = namesFetched + 1 if PROCESSES[NAMES[name].processId] == nil then PROCESSES[NAMES[name].processId] = { @@ -339,9 +341,9 @@ Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg end for processId, process in pairs(PROCESSES) do if PROCESSES[processId].state and PROCESSES[processId].state.lastUpdated and Now - PROCESSES[processId].state.lastUpdated < ARNS_TTL_MS then - print('TTL has not expired yet for ' .. processId) + -- print('TTL has not expired yet for ' .. processId) else - print('Updating state for ' .. processId) + -- print('Updating state for ' .. processId) ao.send({ Target = processId, Action = "State" }) antsResolved = antsResolved + 1 end @@ -375,7 +377,7 @@ Handlers.add("ReceiveANTProcessStateMessage", isANTStateMessage, function(msg) PROCESSES[msg.From].state = state PROCESSES[msg.From].state.lastUpdated = msg.Timestamp - print("Updated " .. msg.From .. " with the latest state.") + print("Resolved ANT " .. msg.From .. " with the latest state.") end) Handlers.add("ACL", Handlers.utils.hasMatchingTag("Action", "ACL"), function(msg) From c5f2abcd88a460e1155488eb302e19dcaa43d7e8 Mon Sep 17 00:00:00 2001 From: vilenarios Date: Thu, 27 Jun 2024 16:28:31 -0400 Subject: [PATCH 6/9] adds cron to resolve all names --- scripts/arns-resolver.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/arns-resolver.lua b/scripts/arns-resolver.lua index 87a599fa..7f37b35c 100644 --- a/scripts/arns-resolver.lua +++ b/scripts/arns-resolver.lua @@ -349,7 +349,8 @@ Handlers.add("ReceiveArNSGetRecordMessage", isArNSGetRecordMessage, function(msg end end end - print("Updated " .. antsResolved .. " ANTs across " .. namesFetched .. " Records") + print("Fetched " .. + namesFetched .. " registered names across " .. antsResolved .. " ANTs. Resolving new ANT processes now.") end) --- Updates stored information with the latest data from ANT-AO process "Info-Notice" messages. @@ -364,7 +365,7 @@ Handlers.add("ReceiveANTProcessStateMessage", isANTStateMessage, function(msg) local owner = state.owner or state.Owner - if PROCESSES[msg.From] ~= nil and PROCESSES[msg.From].Owner ~= nil and PROCESSES[msg.From].Owner ~= owner then + if PROCESSES[msg.From] ~= nil and PROCESSES[msg.From].state and PROCESSES[msg.From].state.Owner ~= nil and PROCESSES[msg.From].state.Owner ~= owner then ACL[PROCESSES[msg.From].Owner][msg.From] = nil end if ACL[owner] == nil then @@ -499,3 +500,11 @@ Handlers.add("Processes", Handlers.utils.hasMatchingTag("Action", "Processes"), Data = json.encode(processes), }) end) + +Handlers.add( + "CronResolveAll", -- handler name + Handlers.utils.hasMatchingTag("Action", "Cron"), -- handler pattern to identify cron message + function() -- handler task to execute on cron message + ao.send({ Target = AR_IO_PROCESS_ID, Action = "Records" }) + end +) From e44d357e8be7f51fbe18f8f98d8850902eae9c18 Mon Sep 17 00:00:00 2001 From: vilenarios Date: Thu, 27 Jun 2024 19:21:13 -0400 Subject: [PATCH 7/9] improves a log message --- scripts/arns-resolver.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/arns-resolver.lua b/scripts/arns-resolver.lua index 7f37b35c..049dbc7d 100644 --- a/scripts/arns-resolver.lua +++ b/scripts/arns-resolver.lua @@ -378,7 +378,7 @@ Handlers.add("ReceiveANTProcessStateMessage", isANTStateMessage, function(msg) PROCESSES[msg.From].state = state PROCESSES[msg.From].state.lastUpdated = msg.Timestamp - print("Resolved ANT " .. msg.From .. " with the latest state.") + print("Resolved " .. state.Ticker .. " with Process ID " .. msg.From .. " with the latest state.") end) Handlers.add("ACL", Handlers.utils.hasMatchingTag("Action", "ACL"), function(msg) From 684dd0ba6a8675d389b8728c34b07beb7655265d Mon Sep 17 00:00:00 2001 From: vilenarios Date: Fri, 28 Jun 2024 12:52:04 -0400 Subject: [PATCH 8/9] improves a log message --- scripts/arns-resolver.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/arns-resolver.lua b/scripts/arns-resolver.lua index 049dbc7d..571ebc12 100644 --- a/scripts/arns-resolver.lua +++ b/scripts/arns-resolver.lua @@ -74,7 +74,7 @@ local arnsMeta = { name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) - return "Getting information for name: " .. rootName + return "Looking up and resolving: " .. rootName end elseif key == "data" then return function(name) From c7eadcba474a6682a69192932d0af4dadd1ddfdb Mon Sep 17 00:00:00 2001 From: vilenarios Date: Fri, 28 Jun 2024 14:31:22 -0400 Subject: [PATCH 9/9] improves a log message --- scripts/arns-resolver.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/arns-resolver.lua b/scripts/arns-resolver.lua index 571ebc12..39743bf7 100644 --- a/scripts/arns-resolver.lua +++ b/scripts/arns-resolver.lua @@ -171,8 +171,8 @@ local arnsMeta = { return function(name) name = string.lower(name) local rootName, underName = splitIntoTwoNames(name) - if NAMES[rootName] == nil then - print("Cannot get process id for name " .. + if NAMES[rootName] == nil or PROCESSES[NAMES[rootName].processId].state == nil then + print("Cannot get full record details for this name " .. rootName .. ", it has not been looked up and resolved yet. Resolving now...") ao.send({ Target = AR_IO_PROCESS_ID, Action = "Record", Name = rootName }) return nil