Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disallow create prmary name req during a records grace period PE-7326 #284

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions spec/arns_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,35 @@ describe("arns", function()
assert.is_false(status)
assert.match("Name must be extended before it can be reassigned", error)
end)

it("should not allow reassigning names during the grace period", function()
-- Setup record in grace period
_G.NameRegistry.records["test-name"] = {
endTimestamp = 123456789,
processId = testProcessId,
purchasePrice = 600000000,
startTimestamp = 0,
type = "lease",
undernameLimit = 10,
}

-- Attempt to reassign
local newProcessId = "test-this-is-valid-arweave-wallet-address-2"
local status, error = pcall(
arns.reassignName,
"test-name",
testProcessId,
-- Just before the grace period ends
123456789
+ constants.gracePeriodMs
- 1,
newProcessId
)

-- Assertions
assert.is_false(status)
assert.match("Name must be extended before it can be reassigned", error)
end)
end)
end

Expand Down
20 changes: 20 additions & 0 deletions spec/primary_names_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ describe("Primary Names", function()
)
end)

it("should fail if the arns record is in its grace period", function()
_G.NameRegistry.records = {
["test"] = {
processId = "base-name-owner",
type = "lease",
endTimestamp = 1234567890,
},
}
local status, err = pcall(
primaryNames.createPrimaryNameRequest,
"test",
"user-requesting-primary-name",
-- Just after grace period starts
1234567890 + 1,
"test-msg-id"
)
assert.is_false(status)
assert.match("ArNS record 'test' is not active", err)
end)

it(
"should create a primary name request and transfer the cost from the initiator to the protocol balance",
function()
Expand Down
13 changes: 6 additions & 7 deletions src/arns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ function arns.pruneReservedNames(currentTimestamp)
end

--- Asserts that a name can be reassigned
--- @param record StoredRecord The record to check
--- @param record StoredRecord | nil The record to check
--- @param currentTimestamp number The current timestamp
--- @param from string The address of the sender
--- @param newProcessId string The new process id
Expand All @@ -1055,11 +1055,11 @@ function arns.assertValidReassignName(record, currentTimestamp, from, newProcess
assert(record.processId == from, "Not authorized to reassign this name")

if record.endTimestamp then
local isWithinGracePeriod = record.endTimestamp < currentTimestamp
and record.endTimestamp + constants.gracePeriodMs > currentTimestamp
local isExpired = record.endTimestamp + constants.gracePeriodMs < currentTimestamp
assert(not isWithinGracePeriod, "Name must be extended before it can be reassigned")
assert(not isExpired, "Name is expired")
assert(
not arns.recordInGracePeriod(record, currentTimestamp),
"Name must be extended before it can be reassigned"
)
assert(not arns.recordExpired(record, currentTimestamp), "Name is expired")
end

return true
Expand All @@ -1075,7 +1075,6 @@ end
function arns.reassignName(name, from, currentTimestamp, newProcessId, allowUnsafeProcessId)
allowUnsafeProcessId = allowUnsafeProcessId or false
local record = arns.getRecord(name)
assert(record, "Name is not registered")
arns.assertValidReassignName(record, currentTimestamp, from, newProcessId, allowUnsafeProcessId)
local updatedRecord = arns.modifyProcessId(name, newProcessId)
return updatedRecord
Expand Down
1 change: 1 addition & 0 deletions src/primary_names.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function primaryNames.createPrimaryNameRequest(name, initiator, timestamp, msgId

local record = arns.getRecord(baseName)
assert(record, "ArNS record '" .. baseName .. "' does not exist")
assert(arns.recordIsActive(record, timestamp), "ArNS record '" .. baseName .. "' is not active")

local requestCost = arns.getTokenCost({
intent = "Primary-Name-Request",
Expand Down
Loading