Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
92fc25c
chore(patch balances): add patch balances work
atticusofsparta Oct 7, 2025
0d0f527
fix(patch): patch balances at end of handler wrapper
atticusofsparta Oct 7, 2025
19d4361
fix(git): ignore mac pointer files
atticusofsparta Oct 7, 2025
43a7a28
fix(patch): simplify balance patching
atticusofsparta Oct 7, 2025
271d965
fix(notes): remove handler balance modification notes
atticusofsparta Oct 7, 2025
4d3c53a
fix(patch): add patch balances hydration handler
atticusofsparta Oct 7, 2025
ceb7a21
fix(events): dont add affected address to the event
atticusofsparta Oct 7, 2025
4d915e0
fix(types): update luadoc types
atticusofsparta Oct 7, 2025
6af1b0d
fix(balances): use a save size checking method
atticusofsparta Oct 7, 2025
8aea00b
fix(patch): add patch file and move patchBalances to its own file to …
atticusofsparta Oct 7, 2025
3fd06b6
fix(balances): revert change to walletHasSufficientQUantity
atticusofsparta Oct 7, 2025
1ff76a3
fix(patching): remove token supply from patch message and fix tests
atticusofsparta Oct 7, 2025
4d2c7b1
fix(tests): add live memory test
atticusofsparta Oct 8, 2025
69350a2
fix(tests): auth issue
atticusofsparta Oct 8, 2025
6b11edd
fix(tests): add configuration for live process testing
atticusofsparta Oct 8, 2025
26b4e44
fix(comments): remove extraneous type
atticusofsparta Oct 8, 2025
68b0fc7
fix(tests): update tests
atticusofsparta Oct 8, 2025
e098651
fix(tests): update integration tests with new patch messages that off…
atticusofsparta Oct 8, 2025
271b6cb
fix(hb): update patchBalances to directly use Balances
atticusofsparta Oct 8, 2025
660739c
fix(test): cleanup unused variables
atticusofsparta Oct 8, 2025
f744578
fix(hb patch): fix pattern function on PatchHyperbeamBalances handler
atticusofsparta Oct 8, 2025
2bcb16c
fix(tests): add tests for patch hyperbeam balances
atticusofsparta Oct 8, 2025
122ffa8
fix(patch file): update hb patch device patch file
atticusofsparta Oct 8, 2025
16e05a5
fix(tests): adjust error handling in patch test
atticusofsparta Oct 8, 2025
377dd8b
fix(tests): add comment on different module id for live memory testing
atticusofsparta Oct 8, 2025
2cd0b34
fix(patch): update patch file to hydrate balances on hb at end of eval
atticusofsparta Oct 8, 2025
faa95de
fix(patch): stringify balances on egress to hb patch device
atticusofsparta Oct 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ coverage

mainnet/**/outputs/*
mainnet/outputs/*
._*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this one all about?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macos pointer file generation when working on an external harddrive

29 changes: 28 additions & 1 deletion src/balances.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,36 @@ end
--- Checks if a wallet has a sufficient balance
--- @param wallet string The address of the wallet
--- @param quantity number The amount to check against the balance
--- @return boolean True if the wallet has a sufficient balance, false otherwise
--- @return table<string, boolean> A table of addresses and whether they have a sufficient balance
function balances.walletHasSufficientBalance(wallet, quantity)
return Balances[wallet] ~= nil and Balances[wallet] >= quantity
end

---@param oldBalances table<string, number> A table of addresses and their balances
---@param newBalances table<string, number> A table of addresses and their balances
function balances.patchBalances(oldBalances, newBalances)
assert(type(oldBalances) == "table", "Old balances must be a table")
assert(type(newBalances) == "table", "New balances must be a table")
local affectedBalancesAddresses = {}
for address, _ in pairs(oldBalances) do
if Balances[address] ~= oldBalances[address] then
affectedBalancesAddresses[address] = true
end
end
for address, _ in pairs(newBalances) do
if oldBalances[address] ~= newBalances[address] then
affectedBalancesAddresses[address] = true
end
end

--- For simplicity we always include the protocol balance in the patch message
local patchMessage = { device = "[email protected]", balances = { [ao.id] = Balances[ao.id] or 0 } }
for address, _ in pairs(affectedBalancesAddresses) do
patchMessage.balances[address] = Balances[address] or 0
end

ao.send(patchMessage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to refresh my memory on how large this can actually scale in HB...

return affectedBalancesAddresses
end

return balances
25 changes: 15 additions & 10 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ local function addEventingHandler(handlerName, pattern, handleFn, critical, prin
critical = critical or false
printEvent = printEvent == nil and true or printEvent
Handlers.add(handlerName, pattern, function(msg)
-- Store the old balances to compare after the handler has run for patching state
local oldBalances = utils.deepCopy(Balances)
-- add an ARIOEvent to the message if it doesn't exist
msg.ioEvent = msg.ioEvent or ARIOEvent(msg)
-- global handler for all eventing errors, so we can log them and send a notice to the sender for non critical errors and discard the memory on critical errors
Expand All @@ -494,6 +496,11 @@ local function addEventingHandler(handlerName, pattern, handleFn, critical, prin
error(errorWithEvent, 0) -- 0 ensures not to include this line number in the error message
end

-- Send patch message to HB
local affectedBalances = balances.patchBalances(oldBalances, Balances)
-- Add affected balances addresses to the event before cleaning up
msg.ioEvent:addField("Affected-Balances-Addresses", utils.getTableKeys(affectedBalances))

msg.ioEvent:addField("Handler-Memory-KiB-Used", collectgarbage("count"), false)
collectgarbage("collect")
msg.ioEvent:addField("Final-Memory-KiB-Used", collectgarbage("count"), false)
Expand Down Expand Up @@ -625,6 +632,7 @@ addEventingHandler(ActionMap.Transfer, utils.hasMatchingTag("Action", ActionMap.
msg.ioEvent:addField("RecipientFormatted", recipient)

local result = balances.transfer(recipient, msg.From, quantity, allowUnsafeAddresses)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

if result ~= nil then
local senderNewBalance = result[msg.From]
local recipientNewBalance = result[recipient]
Expand Down Expand Up @@ -1034,6 +1042,7 @@ addEventingHandler(
},
Data = json.encode(fundFrom and result or recordResult),
})
-- TODO patch other ARIO locations based on FUND
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

end
)

Expand Down Expand Up @@ -1782,6 +1791,7 @@ end, function(msg)
]]
--
print("Ticking from " .. lastCreatedEpochIndex .. " to " .. targetCurrentEpochIndex)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

for epochIndexToTick = lastCreatedEpochIndex, targetCurrentEpochIndex do
local tickResult = tick.tickEpoch(msg.Timestamp, blockHeight, hashchain, msgId, epochIndexToTick)
if tickResult.pruneGatewaysResult ~= nil then
Expand Down Expand Up @@ -2137,17 +2147,12 @@ end)
-- Pagination handlers

addEventingHandler("paginatedRecords", function(msg)
return msg.Action == "Paginated-Records" or msg.Action == ActionMap.Records
return msg.Action == "Paginated-Records" or msg.Action == ActionMap.Records
end, function(msg)
local page = utils.parsePaginationTags(msg)
local result = arns.getPaginatedRecords(
page.cursor,
page.limit,
page.sortBy or "startTimestamp",
page.sortOrder,
page.filters
)
Send(msg, { Target = msg.From, Action = "Records-Notice", Data = json.encode(result) })
local page = utils.parsePaginationTags(msg)
local result =
arns.getPaginatedRecords(page.cursor, page.limit, page.sortBy or "startTimestamp", page.sortOrder, page.filters)
Send(msg, { Target = msg.From, Action = "Records-Notice", Data = json.encode(result) })
end)

addEventingHandler("paginatedGateways", function(msg)
Expand Down
Loading