Skip to content

Commit

Permalink
Merge pull request #69 from primevprotocol/ckartik/add-new-oracle-and…
Browse files Browse the repository at this point in the history
…-test

Updates Oracle to allow per commitment Settlement at a time
  • Loading branch information
kant777 authored Dec 27, 2023
2 parents 46f3705 + b035109 commit 1691095
Show file tree
Hide file tree
Showing 2 changed files with 306 additions and 155 deletions.
66 changes: 29 additions & 37 deletions contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ contract Oracle is Ownable {
// mapping of txns to bool to check if txns exists
// Stores all proccessed txns for onw
// TODO(@ckartik): This may be too restricvie in the log run as an appraoch
mapping(string => bool) txnHashes;
// mapping(string => bool) txnHashes;


// Event to request block data
event BlockDataRequested(uint256 blockNumber);
// // Event to request block data
// event BlockDataRequested(uint256 blockNumber);

// Event to signal the reception of block data
event BlockDataReceived(
string[] txnList,
uint256 blockNumber,
string blockBuilderName
);
// // Event to signal the reception of block data
// event BlockDataReceived(
// string[] txnList,
// uint256 blockNumber,
// string blockBuilderName
// );

// Event to signal the processing of a commitment
event CommitmentProcessed(bytes32 commitmentHash, bool isSlash);
Expand All @@ -75,47 +75,39 @@ contract Oracle is Ownable {
blockBuilderNameToAddress[builderName] = builderAddress;
}

// Function to request the block data
function requestBlockData(uint256 blockNumber) external {
// Emit an event that data request has been made
emit BlockDataRequested(blockNumber);

function getBuilder(string calldata builderNameGrafiti) external view returns (address) {
return blockBuilderNameToAddress[builderNameGrafiti];
}

// Function to receive and process the block data (this would be automated in a real-world scenario)
// TODO(@ckartik): Should restrict who can make this call
function receiveBlockData(
string[] calldata txnList,
function processBuilderCommitmentForBlockNumber(
bytes32 commitmentIndex,
uint256 blockNumber,
string calldata blockBuilderName
string calldata blockBuilderName,
bool isSlash
) external {
// Emit an event that the block data has been received
emit BlockDataReceived(txnList, blockNumber, blockBuilderName);
// Check grafiti against registered builder IDs
address builder = blockBuilderNameToAddress[blockBuilderName];

for (uint256 i = 0; i < txnList.length; i++) {
txnHashes[txnList[i]] = true;
IPreConfCommitmentStore.PreConfCommitment memory commitment = preConfContract.getCommitment(commitmentIndex);
if (commitment.commiter == builder) {
this.processCommitment(commitmentIndex, isSlash);
}

// Placeholder: Process the block data and determine the commitment's validity
// For demonstration, we'll call this with a dummy commitment hash and isSlash flag
bytes32[] memory commitmentHashes = preConfContract.getCommitmentsByBlockNumber(blockNumber);
for (uint256 i = 0; i < commitmentHashes.length; i++) {
IPreConfCommitmentStore.PreConfCommitment memory commitment = preConfContract.getCommitment(commitmentHashes[i]);
if (commitment.commiter == builder) {
if (txnHashes[commitment.txnHash]){
this.processCommitment(commitmentHashes[i], false);
}
else {
this.processCommitment(commitmentHashes[i], true);
}
}
}
}

if (nextRequestedBlockNumber <= blockNumber) {
nextRequestedBlockNumber = blockNumber + 1;
}
function setNextBlock(uint64 newBlockNumber) external {
nextRequestedBlockNumber = newBlockNumber;
}

function moveToNextBlock() external {
nextRequestedBlockNumber++;
}



// Function to simulate the processing of a commitment (initiate a slash or a reward)
function processCommitment(bytes32 commitmentIndex, bool isSlash) external {
if (isSlash) {
Expand Down
Loading

0 comments on commit 1691095

Please sign in to comment.