Skip to content
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
22 changes: 13 additions & 9 deletions src/reporters/OOReporter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,20 @@ contract OOReporter is

/// @inheritdoc IOOReporter
function updateRequestRules(bytes32 requestId, bytes calldata updatedRules) external onlyRequester {
RequestData storage request = _requireRegistered(requestId);
bytes32 canonicalRequestId = _canonicalRequestId(requestId);
RequestData storage request = _getStorage().requests[canonicalRequestId];
if (request.resolved) revert RequestAlreadyResolved();
if (msg.sender != request.requester) revert CallerNotRequestRegistrar();

optimisticOracle().updateRequestRules(request.priceIdentifier, request.requestRules, updatedRules);

emit RequestRulesUpdated(requestId, block.timestamp, msg.sender, updatedRules);
emit RequestRulesUpdated(canonicalRequestId, block.timestamp, msg.sender, updatedRules);
}

/// @inheritdoc IOOReporter
function setRequestReward(bytes32 requestId, uint256 newReward) external onlyOracleInitializer {
RequestData storage request = _requireRegistered(requestId);
bytes32 canonicalRequestId = _canonicalRequestId(requestId);
RequestData storage request = _getStorage().requests[canonicalRequestId];
if (!request.initialized) revert RequestNotInitialized();
if (request.resolved) revert RequestAlreadyResolved();

Expand All @@ -297,7 +299,7 @@ contract OOReporter is
oracle.setReward(request.priceIdentifier, request.requestTimestamp, request.requestRules, newReward);

emit RequestRewardUpdated(
requestId, request.requestTimestamp, msg.sender, address(currency), oldReward, newReward
canonicalRequestId, request.requestTimestamp, msg.sender, address(currency), oldReward, newReward
);
}

Expand Down Expand Up @@ -338,7 +340,7 @@ contract OOReporter is
_requestPrice(request.priceIdentifier, requestTimestamp, request.requestRules, reward, proposalBond, liveness);

emit RequestInitialized(
requestId,
canonicalRequestId,
requestTimestamp,
msg.sender,
request.priceIdentifier,
Expand All @@ -356,7 +358,8 @@ contract OOReporter is
external
onlyOracleInitializer
{
RequestData storage request = _requireRegistered(requestId);
bytes32 canonicalRequestId = _canonicalRequestId(requestId);
RequestData storage request = _getStorage().requests[canonicalRequestId];
if (!request.initialized) revert RequestNotInitialized();
if (request.resolved) revert RequestAlreadyResolved();
if (!request.rerequestAllowed) revert RequestRerequestNotAllowed();
Expand All @@ -367,12 +370,13 @@ contract OOReporter is

request.manualRerequestsRemaining -= 1;

_emitRequestRerequested(requestId, request, previousRequestTimestamp, msg.sender, RerequestType.Manual);
_emitRequestRerequested(canonicalRequestId, request, previousRequestTimestamp, msg.sender, RerequestType.Manual);
}

/// @inheritdoc IOOReporter
function setRequestRerequestBudget(bytes32 requestId, uint256 newManualRerequestsRemaining) external onlyOwner {
RequestData storage request = _requireRegistered(requestId);
bytes32 canonicalRequestId = _canonicalRequestId(requestId);
RequestData storage request = _getStorage().requests[canonicalRequestId];
if (!request.initialized) revert RequestNotInitialized();
if (request.resolved) revert RequestAlreadyResolved();
uint256 budgetCeiling = defaultRerequestBudget();
Expand All @@ -385,7 +389,7 @@ contract OOReporter is

request.manualRerequestsRemaining = newManualRerequestsRemaining;

emit RequestRerequestBudgetSet(requestId, newManualRerequestsRemaining);
emit RequestRerequestBudgetSet(canonicalRequestId, newManualRerequestsRemaining);
}

/// @notice Managed OO dispute callback. Attempts one auto re-request, otherwise opens the manual gate.
Expand Down
22 changes: 17 additions & 5 deletions src/reporters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,21 @@ replacement request. Automatic re-requests reuse the active reward, proposal bon
the default budget for future initializations and P4 refreshes with `setDefaultRerequestBudget(...)`, and can adjust an
active unresolved request's current manual budget with `setRequestRerequestBudget(...)`.

Lifecycle events that refer to a specific Managed OO request consistently lead with the external `requestId` and then
the active OO `requestTimestamp` before actor or outcome fields. This keeps initialization, re-request,
re-request-gate, rules-update, and resolution logs easy to correlate after a request has been replaced.
Shared lifecycle events use the canonical request ID (the first ID registered for the tuple), even when the caller
supplies a duplicate ID. This applies to `RequestInitialized`, `RequestRulesUpdated`, `RequestRewardUpdated`,
`RequestRerequested`, `RequestRerequestAllowed`, `AutomaticRerequestFailed`, and `RequestRerequestBudgetSet`.
`ResolutionCallbacksFailed` also identifies the canonical request whose callback batch reverted.

`RequestRegistered`, `RequestResolved`, and the Polymarket callback success/failure events identify individual external
request IDs. A duplicate does not receive a separate initialization or re-request event. Indexers should map each
`RequestRegistered` tuple to its canonical ID using `getRequestId(priceIdentifier, requestRules)` and follow that ID's
shared lifecycle. Shared lifecycle events do not include the caller-supplied alias.

`RequestResolved` records outcome availability, not successful delivery to a module. It has at-least-once semantics:
after a callback batch reverts, initializing a duplicate whose initialization flag was rolled back can emit it again.
Consumers should deduplicate resolutions by `(reporter address, requestId, requestTimestamp)`. A
`ResolutionCallbacksFailed` event means all callback effects and individual callback events in that batch were rolled
back; operators must check and recover reporting for every linked ID.

## Bond And Liveness Events

Expand Down Expand Up @@ -207,8 +219,8 @@ Rules updates do not replace the original registered rules or create a new `(pri
lookup alias. Consumers should use `requestId` as the stable reporter identity and read canonical update history from the
Managed OO using the reporter address plus the original `(priceIdentifier, requestRules)` tuple.

The reporter additionally emits a `RequestRulesUpdated` event carrying the requester-facing `requestId` and updater
address for self-contained logs.
The reporter additionally emits a `RequestRulesUpdated` event carrying the canonical `requestId` and updater address,
even when the update was submitted through a duplicate ID.

For a registered request, updates can be forwarded before or after Managed OO initialization. The reporter rejects rules
updates after the request has resolved.
Expand Down
22 changes: 13 additions & 9 deletions src/reporters/interfaces/IOOReporter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ interface IOOReporter {
uint64 minimumLiveness,
uint64 maximumLiveness
);
/// @notice Emitted when an approved oracle initializer creates the first Managed OO request.
/// @notice Emitted under the canonical request ID when the first shared Managed OO request is created.
/// @dev proposalBond and liveness are reporter-requested parameters. Effective proposal-time values can differ
/// if Managed OO request-manager preconfigs apply.
event RequestInitialized(
Expand All @@ -165,11 +165,11 @@ interface IOOReporter {
uint64 liveness,
uint256 manualRerequestsRemaining
);
/// @notice Emitted when the registering requester posts updated request rules for offchain consumers.
/// @notice Emitted under the canonical request ID when the requester posts shared request rules updates.
event RequestRulesUpdated(
bytes32 indexed requestId, uint256 indexed timestamp, address indexed updater, bytes updatedRules
);
/// @notice Emitted when an approved oracle initializer updates the active Managed OO request reward.
/// @notice Emitted under the canonical request ID when the active shared Managed OO request reward changes.
event RequestRewardUpdated(
bytes32 indexed requestId,
uint256 indexed requestTimestamp,
Expand All @@ -179,19 +179,22 @@ interface IOOReporter {
uint256 newReward
);
/// @notice Emitted when a final raw UMA outcome is stored for a request.
/// @dev Events for every linked request ID are emitted before the isolated callback batch.
/// @dev Emitted for every linked request ID before the isolated callback batch; this does not confirm delivery.
/// Recovery via duplicate initialization can re-emit this event after a reverted batch. Consumers should
/// deduplicate by (reporter address, requestId, requestTimestamp).
event RequestResolved(bytes32 indexed requestId, uint256 indexed requestTimestamp, int256 outcome);
/// @notice Emitted when the isolated request-ID callback fan-out reverts after all resolution events are emitted.
/// @notice Emitted under the canonical request ID when the callback batch reverts after resolution events.
/// @dev All callback effects and per-ID callback events from the reverted batch are rolled back.
event ResolutionCallbacksFailed(bytes32 indexed requestId, uint256 indexed requestTimestamp);
/// @notice Emitted when a callback opens the oracle-initializer re-request path.
/// @notice Emitted under the canonical request ID when a callback opens the shared manual re-request path.
event RequestRerequestAllowed(
bytes32 indexed requestId, uint256 indexed requestTimestamp, RerequestTrigger indexed trigger
);
/// @notice Emitted when an automatic re-request fails and the callback falls back to the manual gate.
/// @notice Emitted under the canonical request ID when an automatic re-request fails and opens the manual gate.
event AutomaticRerequestFailed(
bytes32 indexed requestId, uint256 indexed requestTimestamp, RerequestType indexed rerequestType
);
/// @notice Emitted when the reporter creates a replacement Managed OO request.
/// @notice Emitted under the canonical request ID when the reporter creates a replacement Managed OO request.
/// @dev proposalBond and liveness are reporter-requested parameters. Effective proposal-time values can differ
/// if Managed OO request-manager preconfigs apply.
event RequestRerequested(
Expand All @@ -206,7 +209,8 @@ interface IOOReporter {
uint64 liveness,
uint256 manualRerequestsRemaining
);
/// @notice Emitted when the owner updates the remaining re-request budget for one request.
/// @notice Emitted under the canonical request ID when the shared remaining re-request budget changes.
/// @dev Emitted for owner updates and automatic refills to the default budget on P4 settlement.
event RequestRerequestBudgetSet(bytes32 indexed requestId, uint256 manualRerequestsRemaining);
/// @notice Emitted when the owner sweeps ERC20 or native token funds from the reporter.
event FundsSwept(address indexed token, address indexed recipient, uint256 amount);
Expand Down
86 changes: 86 additions & 0 deletions test/reporters/OOReporter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,92 @@ contract OOReporterTest {
assertTrue(optimisticOracle.getMockRequest(requestKey).requested, "canonical OO request should exist");
}

function test_duplicateOperationsEmitCanonicalLifecycleEvents() external {
bytes memory requestRules = _requestRules("primary");
_registerRequest(REQUEST_ID, BINARY_IDENTIFIER, requestRules);
_registerRequest(SECOND_REQUEST_ID, BINARY_IDENTIFIER, requestRules);
uint256 initialTimestamp = vm.getBlockTimestamp();

vm.expectEmit(address(reporter));
emit IOOReporter.RequestInitialized(
REQUEST_ID,
initialTimestamp,
oracleInitializer,
BINARY_IDENTIFIER,
requestRules,
address(usdc),
0,
PROPOSAL_BOND,
LIVENESS,
DEFAULT_REREQUEST_BUDGET
);
vm.prank(oracleInitializer);
reporter.initializeRequest(SECOND_REQUEST_ID, 0, PROPOSAL_BOND, LIVENESS);

bytes memory updatedRules = bytes("clarified rules");
vm.expectEmit(address(reporter));
emit RequestRulesUpdated(REQUEST_ID, initialTimestamp, requester, updatedRules);
vm.prank(requester);
reporter.updateRequestRules(SECOND_REQUEST_ID, updatedRules);

usdc.mint(address(reporter), REWARD);
vm.expectEmit(address(reporter));
emit RequestRewardUpdated(REQUEST_ID, initialTimestamp, oracleInitializer, address(usdc), 0, REWARD);
vm.prank(oracleInitializer);
reporter.setRequestReward(SECOND_REQUEST_ID, REWARD);

vm.expectEmit(address(reporter));
emit RequestRerequestBudgetSet(REQUEST_ID, 2);
vm.prank(owner);
reporter.setRequestRerequestBudget(SECOND_REQUEST_ID, 2);

vm.warp(initialTimestamp + 1);
vm.expectEmit(address(reporter));
emit RequestRerequested(
REQUEST_ID,
initialTimestamp + 1,
address(reporter),
RerequestType.AutomaticDispute,
initialTimestamp,
address(usdc),
REWARD,
PROPOSAL_BOND,
LIVENESS,
2
);
optimisticOracle.disputePrice(address(reporter), BINARY_IDENTIFIER, initialTimestamp, requestRules);

vm.warp(initialTimestamp + 2);
vm.expectEmit(address(reporter));
emit RequestRerequestAllowed(REQUEST_ID, initialTimestamp + 1, RerequestTrigger.Dispute);
optimisticOracle.disputePrice(address(reporter), BINARY_IDENTIFIER, initialTimestamp + 1, requestRules);

vm.expectEmit(address(reporter));
emit RequestRerequested(
REQUEST_ID,
initialTimestamp + 2,
oracleInitializer,
RerequestType.Manual,
initialTimestamp + 1,
address(usdc),
REWARD,
PROPOSAL_BOND,
LIVENESS,
1
);
vm.prank(oracleInitializer);
reporter.rerequest(SECOND_REQUEST_ID, REWARD, PROPOSAL_BOND, LIVENESS);

RequestData memory canonical = reporter.getRequest(REQUEST_ID);
assertEq(canonical.requestTimestamp, initialTimestamp + 2, "shared request should advance");
assertEq(canonical.manualRerequestsRemaining, 1, "shared budget should decrement");
assertEq(
keccak256(abi.encode(reporter.getRequest(SECOND_REQUEST_ID))),
keccak256(abi.encode(canonical)),
"alias should share the event's canonical state"
);
}

function test_initializeRequestRejectsZeroLiveness() external {
_registerRequest(REQUEST_ID, BINARY_IDENTIFIER, _requestRules("primary"));

Expand Down
Loading