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

Review of superseded feature #2315

Merged
Merged
Changes from 1 commit
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
62 changes: 54 additions & 8 deletions contracts/v0.2/src/SubmissionProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,16 @@ contract SubmissionProxy is Ownable {
}
}

function submitStrict(
/**
* @notice Submit a batch of answers to multiple feeds. If any
* of the answers do not meet required conditions the
* whole batch is reverted.
* @param _feedHashes The hashes of the feeds
* @param _answers The submissions
* @param _timestamps The unixmilli timestamps of the proofs
* @param _proofs The proofs
*/
function submitStrictBatch(
bytes32[] calldata _feedHashes,
int256[] calldata _answers,
uint256[] calldata _timestamps,
Expand All @@ -412,16 +421,26 @@ contract SubmissionProxy is Ownable {

uint256 feedsLength_ = _feedHashes.length;
for (uint256 i = 0; i < feedsLength_; i++) {
submitSingle(_feedHashes[i], _answers[i], _timestamps[i], _proofs[i]);
submitStrictSingle(_feedHashes[i], _answers[i], _timestamps[i], _proofs[i]);
}
}

function submitSingle(bytes32 _feedHash, int256 _answer, uint256 _timestamp, bytes calldata _proof) public {
if (_timestamp <= (block.timestamp - dataFreshness) * 1000 ) {
/**
* @notice Submit a single answer to a feed. The answer is
* reverted if any of the required conditions are not met.
* @param _feedHash The hash of the feed
* @param _answer The submission
* @param _timestamp The unixmilli timestamp of the proof
* @param _proof The proof
*/
function submitStrictSingle(bytes32 _feedHash, int256 _answer, uint256 _timestamp, bytes calldata _proof) public {
if (_timestamp <= (block.timestamp - dataFreshness) * 1000) {
// answer is not fresh -> do not submit!
revert AnswerOutdated();
}

if (lastSubmissionTimes[_feedHash] >= _timestamp) {
// answer is superseeded -> do not submit!
revert AnswerSuperseded();
}

Expand Down Expand Up @@ -450,8 +469,21 @@ contract SubmissionProxy is Ownable {
}
}

// works same as submit, but will only return error if the proof is invalid, ignore if answer is superseded
function updatePrices(bytes32[] calldata _feedHashes, int256[] calldata _answers, uint256[] calldata _timestamps, bytes[] calldata _proofs) public {
/**
* @notice Submit a batch of answers to multiple feeds. The answers are
* ignored if they have been superseeded. If any of the answers do not
* meet the rest of required conditions the whole batch is reverted.
* @param _feedHashes The hashes of the feeds
* @param _answers The submissions
* @param _timestamps The unixmilli timestamps of the proofs
* @param _proofs The proofs
*/
function updatePrices(
bytes32[] calldata _feedHashes,
int256[] calldata _answers,
uint256[] calldata _timestamps,
bytes[] calldata _proofs
) public {
if (
_feedHashes.length != _answers.length || _answers.length != _proofs.length
|| _proofs.length != _timestamps.length || _feedHashes.length > maxSubmission
Expand All @@ -465,9 +497,23 @@ contract SubmissionProxy is Ownable {
}
}


/**
* @notice Submit a single submission to a feed. The submission is
* ignored if it has been superseeded. If the submission does not
* meet the rest of required conditions the submission is reverted.
* @param _feedHash The hash of the feed
* @param _answer The submission
* @param _timestamp The unixmilli timestamp of the proof
* @param _proof The proof
*/
function updatePrice(bytes32 _feedHash, int256 _answer, uint256 _timestamp, bytes calldata _proof) public {
if (_timestamp <= (block.timestamp - dataFreshness) * 1000 ) {
if (lastSubmissionTimes[_feedHash] >= _timestamp) {
// answer is superseeded -> skip submission
return;
}

if (_timestamp <= (block.timestamp - dataFreshness) * 1000) {
// answer is not fresh -> do not submit!
revert AnswerOutdated();
}

Expand Down
Loading