Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
467960d
arkscript: Define and validate the channel VTXO policy
sputn1ck Nov 24, 2026
9066d85
serverconn: Isolate durable RPC identity and reply evidence
sputn1ck Nov 9, 2026
c0d6198
sdk/swaps: Separate receive polling and acceptance deadlines
sputn1ck Nov 9, 2026
6a34181
rpc: Define optional full-package refund authorization
sputn1ck Nov 24, 2026
95e3319
rpc: Generate additive refund bindings
sputn1ck Nov 24, 2026
21063dc
oor: Bind cooperative signatures to both payout transactions
sputn1ck Nov 24, 2026
edfdc21
sdk/swaps: Keep ordinary refunds on the legacy contract
sputn1ck Nov 24, 2026
7bdb186
multi: Assemble independent wallet and swap review prerequisites
sputn1ck Nov 24, 2026
ec6ce81
oor: Add prepared transfer boundary
sputn1ck Aug 24, 2026
3cab633
multi: Track channel recovery sources
sputn1ck Aug 24, 2026
4135cc5
oor: Preserve prepared transfer identity after restart
sputn1ck Sep 8, 2026
043af6c
db: Allow recovery expiry selection before replay
sputn1ck Sep 8, 2026
0b2b401
oor: Derive pre-PONR failures from protocol phase
sputn1ck Sep 8, 2026
3952514
oor: Reject unknown future snapshot versions
sputn1ck Sep 8, 2026
aa2d39a
unroll: Route durable channel exit policies
sputn1ck Sep 8, 2026
b839113
unroll: Infer parent height from pre-signed spend
sputn1ck Sep 8, 2026
35e5b60
oor: Reload committed state before answering status queries
sputn1ck Nov 16, 2026
9e93b10
oor: Cover failed outgoing session identity on retry
sputn1ck Nov 16, 2026
4e1d01e
unroll: Terminalize foreign spends of asset targets
sputn1ck Nov 16, 2026
1796a8a
multi: Clarify channel policy and recovery deadlines
sputn1ck Nov 16, 2026
1eae23a
oor: Fence prepared abort replay with reservation epochs
sputn1ck Nov 16, 2026
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
43 changes: 43 additions & 0 deletions db/oor_session_registry_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,49 @@ func (s *OORSessionRegistryStoreDB) GetSession(ctx context.Context,
return record, nil
}

// GetUnfailedSessionByIdempotencyKey loads a durable outgoing identity before
// an immutable dispatch attempt exists. Failed rows deliberately release the
// key; pending and completed rows retain it.
func (s *OORSessionRegistryStoreDB) GetUnfailedSessionByIdempotencyKey(
ctx context.Context, key string) (*OORSessionRegistryRecord, error) {

if key == "" {
return nil, ErrOORSessionNotFound
}

var record *OORSessionRegistryRecord
readFn := func(q *sqlc.Queries) error {
row, err := q.GetUnfailedOORSessionRegistryByIdempotencyKey(
ctx, sql.NullString{
String: key,
Valid: true,
},
)
if err != nil {
return err
}

converted, err := oorSessionRecordFromRow(row)
if err != nil {
return err
}

record = &converted

return nil
}

err := s.ExecTx(ctx, ReadTxOption(), readFn)
if errors.Is(err, sql.ErrNoRows) {
return nil, ErrOORSessionNotFound
}
if err != nil {
return nil, err
}

return record, nil
}

// GetDispatchAttemptByIdempotencyKey loads the immutable outgoing dispatch
// bound to key. Unlike the mutable session lookup, it remains valid across
// terminal and incoming lifecycle updates.
Expand Down
45 changes: 45 additions & 0 deletions db/oor_session_registry_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,51 @@ func TestOORSessionRegistryGetNotFound(t *testing.T) {
require.ErrorIs(t, err, ErrOORSessionNotFound)
}

// TestOORSessionRegistryLookupPreparedIdentity verifies that the caller key is
// queryable before the first dispatch attempt is persisted. This is the
// durable identity boundary for prepare-only OOR sessions across restarts.
func TestOORSessionRegistryLookupPreparedIdentity(t *testing.T) {
t.Parallel()

ctx := t.Context()
store := newOORSessionRegistryStoreForTest(t)
sid := sessionHash(0x03)
record := OORSessionRegistryRecord{
SessionID: sid,
ActorID: "actor-" + sid.String(),
Direction: OORSessionDirectionOutgoing,
Phase: "prepared",
IdempotencyKey: "prepared-key",
Status: OORSessionStatusPending,
SnapshotData: []byte{
0x01,
},
SnapshotVersion: 1,
}
require.NoError(t, store.UpsertSession(ctx, record))

got, err := store.GetUnfailedSessionByIdempotencyKey(
ctx, record.IdempotencyKey,
)
require.NoError(t, err)
require.Equal(t, sid, got.SessionID)
require.Equal(t, "prepared", got.Phase)

_, err = store.GetDispatchAttemptByIdempotencyKey(
ctx, record.IdempotencyKey,
)
require.ErrorIs(t, err, ErrOORDispatchAttemptNotFound)

record.Status = OORSessionStatusFailed
record.Phase = "failed"
require.NoError(t, store.UpsertSession(ctx, record))

_, err = store.GetUnfailedSessionByIdempotencyKey(
ctx, record.IdempotencyKey,
)
require.ErrorIs(t, err, ErrOORSessionNotFound)
}

// TestOORSessionRegistryUpsertUpdates verifies a second upsert advances the
// mutable fields while preserving the original created_at.
func TestOORSessionRegistryUpsertUpdates(t *testing.T) {
Expand Down
59 changes: 58 additions & 1 deletion db/oor_unroll_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,72 @@ type unrollPackageNode struct {
func (s *OORArtifactPersistenceStore) ResolveUnrollPackages(ctx context.Context,
outpoint wire.OutPoint) (*OORUnrollPackages, error) {

return s.resolveUnrollPackages(
ctx, outpoint,
func(ctx context.Context, q OORArtifactStore) (
*OORPackageBundle, error) {

return loadPackageBundleByOutpoint(ctx, q, outpoint)
},
)
}

// ResolveUnrollPackagesBySessionID resolves a package chain before the local
// endpoint has installed an outpoint binding. OOR senders use this while
// promoting a recipient output into shared channel recovery state.
func (s *OORArtifactPersistenceStore) ResolveUnrollPackagesBySessionID(
ctx context.Context, outpoint wire.OutPoint, sessionID chainhash.Hash) (
*OORUnrollPackages, error) {

if sessionID != outpoint.Hash {
return nil, fmt.Errorf("target outpoint %s does not match OOR "+
"session %s", outpoint, sessionID)
}

return s.resolveUnrollPackages(
ctx, outpoint,
func(ctx context.Context, q OORArtifactStore) (
*OORPackageBundle, error) {

pkg, err := loadPackageBundleBySessionID(
ctx, q, sessionID,
)
if err != nil {
return nil, err
}
if !packageProducesAncestorOutput(
pkg, outpoint.Hash, outpoint.Index,
) {
return nil, fmt.Errorf("OOR session %s does "+
"not create target outpoint %s",
sessionID, outpoint)
}

return pkg, nil
},
)
}

// resolveUnrollPackages traverses one package chain from a caller-selected
// target loader. The target outpoint remains part of the result even when the
// first package is known only by session ID.
func (s *OORArtifactPersistenceStore) resolveUnrollPackages(ctx context.Context,
outpoint wire.OutPoint,
loadTarget func(context.Context, OORArtifactStore) (*OORPackageBundle,
error)) (*OORUnrollPackages, error) {

if s == nil || s.db == nil {
return nil, fmt.Errorf("store must be provided")
}
if loadTarget == nil {
return nil, fmt.Errorf("target package loader must be provided")
}

readTx := ReadTxOption()
var result *OORUnrollPackages

err := s.db.ExecTx(ctx, readTx, func(q OORArtifactStore) error {
targetPkg, err := loadPackageBundleByOutpoint(ctx, q, outpoint)
targetPkg, err := loadTarget(ctx, q)
if err != nil {
return err
}
Expand Down
37 changes: 37 additions & 0 deletions db/oor_unroll_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,43 @@ func TestResolveUnrollPackagesUnknownOutpoint(t *testing.T) {
require.True(t, errors.Is(err, sql.ErrNoRows))
}

// TestResolveUnrollPackagesBySessionID verifies an OOR sender can resolve the
// recipient output before shared channel recovery state creates a local VTXO
// row and output binding.
func TestResolveUnrollPackagesBySessionID(t *testing.T) {
t.Parallel()

ctx := t.Context()
store, _ := newOORArtifactStoreForTest(t)
sessionID, arkPSBT, checkpoints, outpoint, _, _, unresolvedInput :=
buildTestOORPackage(t, 0x31)

err := store.UpsertPackage(
ctx, OORPackageDirectionOutgoing, sessionID, arkPSBT,
checkpoints,
)
require.NoError(t, err)

resolved, err := store.ResolveUnrollPackagesBySessionID(
ctx, outpoint, sessionID,
)
require.NoError(t, err)
require.Equal(t, outpoint, resolved.TargetOutpoint)
require.Len(t, resolved.Packages, 1)
require.Equal(t, sessionID, resolved.Packages[0].SessionID)
require.Equal(
t, []wire.OutPoint{unresolvedInput},
resolved.UnresolvedCheckpointInputs,
)

wrongSession := sessionID
wrongSession[0] ^= 1
_, err = store.ResolveUnrollPackagesBySessionID(
ctx, outpoint, wrongSession,
)
require.ErrorContains(t, err, "does not match OOR session")
}

// TestResolveUnrollPackagesWithKnownAncestor verifies that resolver traversal
// returns a deterministic ancestor-first package chain and surfaces unresolved
// outermost checkpoint inputs.
Expand Down
3 changes: 3 additions & 0 deletions db/round_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ type RoundStore interface {
ctx context.Context, arg sqlc.UpdateVTXOStatusParams,
) error

SetRecoveryOnlyVTXORelativeExpiry(ctx context.Context,
arg sqlc.SetRecoveryOnlyVTXORelativeExpiryParams) (int64, error)

// DeleteSpendingReservation removes a spending-reservation row so the
// VTXO store can atomically update a VTXO's status and drop its
// reservation in the same transaction when it leaves SpendingState.
Expand Down
2 changes: 2 additions & 0 deletions db/sqlc/migrations/000004_vtxos.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ CREATE TABLE IF NOT EXISTS vtxos (
-- 5 = UnilateralExit
-- 6 = Failed
-- 7 = Spending
-- 8 = Expired
-- 9 = RecoveryOnly
status INTEGER NOT NULL DEFAULT 0,

-- forfeit_round_id is the round in which this VTXO is being forfeited.
Expand Down
27 changes: 27 additions & 0 deletions db/sqlc/oor_session_registry.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions db/sqlc/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions db/sqlc/queries/oor_session_registry.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ SELECT * FROM oor_session_registry
WHERE session_id = $1
;

-- name: GetUnfailedOORSessionRegistryByIdempotencyKey :one
SELECT * FROM oor_session_registry
WHERE idempotency_key = $1 AND status != 2
ORDER BY created_at ASC
LIMIT 1
;

-- name: ListNonTerminalOORSessionRegistry :many
-- Status 1 = Completed, 2 = Failed (anchored to Go iota in
-- db/oor_session_registry_store.go OORSessionStatus).
Expand Down
8 changes: 8 additions & 0 deletions db/sqlc/queries/vtxo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ WHERE outpoint_hash = $1 AND outpoint_index = $2
AND batch_expiry = $4
AND (created_height = $5 OR created_height = $3);

-- name: SetRecoveryOnlyVTXORelativeExpiry :execrows
-- Selects the exact final-spend delay for an application-owned recovery row.
-- Ordinary wallet VTXOs can never be modified through this query.
UPDATE vtxos
SET expiry = $3,
last_update_time = $4
WHERE outpoint_hash = $1 AND outpoint_index = $2 AND status = 9;

-- name: MarkVTXOForfeiting :exec
-- MarkVTXOForfeiting transitions a VTXO to Forfeiting status and persists
-- the forfeit round ID and transaction for crash recovery. Called when
Expand Down
2 changes: 2 additions & 0 deletions db/sqlc/schemas/generated_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,8 @@ CREATE TABLE vtxos (
-- 5 = UnilateralExit
-- 6 = Failed
-- 7 = Spending
-- 8 = Expired
-- 9 = RecoveryOnly
status INTEGER NOT NULL DEFAULT 0,

-- forfeit_round_id is the round in which this VTXO is being forfeited.
Expand Down
29 changes: 29 additions & 0 deletions db/sqlc/vtxo.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading