Skip to content

Commit

Permalink
chore: deleting state after usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikelle committed May 22, 2024
1 parent b3a1858 commit 4b344de
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 579 deletions.
157 changes: 2 additions & 155 deletions contracts-abi/abi/PreConfCommitmentStore.abi
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,6 @@
],
"stateMutability": "view"
},
{
"type": "function",
"name": "blockCommitments",
"inputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "blockTracker",
Expand All @@ -135,20 +111,7 @@
},
{
"type": "function",
"name": "commitmentCount",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "commitment_dispatch_window",
"name": "commitmentDispatchWindow",
"inputs": [],
"outputs": [
{
Expand All @@ -170,11 +133,6 @@
}
],
"outputs": [
{
"name": "commitmentUsed",
"type": "bool",
"internalType": "bool"
},
{
"name": "bidder",
"type": "address",
Expand Down Expand Up @@ -273,11 +231,6 @@
}
],
"outputs": [
{
"name": "commitmentUsed",
"type": "bool",
"internalType": "bool"
},
{
"name": "commiter",
"type": "address",
Expand Down Expand Up @@ -356,11 +309,6 @@
"type": "tuple",
"internalType": "struct PreConfCommitmentStore.PreConfCommitment",
"components": [
{
"name": "commitmentUsed",
"type": "bool",
"internalType": "bool"
},
{
"name": "bidder",
"type": "address",
Expand Down Expand Up @@ -440,11 +388,6 @@
"type": "tuple",
"internalType": "struct PreConfCommitmentStore.PreConfCommitment",
"components": [
{
"name": "commitmentUsed",
"type": "bool",
"internalType": "bool"
},
{
"name": "bidder",
"type": "address",
Expand Down Expand Up @@ -522,44 +465,6 @@
],
"stateMutability": "pure"
},
{
"type": "function",
"name": "getCommitmentsByBlockNumber",
"inputs": [
{
"name": "blockNumber",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "bytes32[]",
"internalType": "bytes32[]"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getCommitmentsByCommitter",
"inputs": [
{
"name": "commiter",
"type": "address",
"internalType": "address"
}
],
"outputs": [
{
"name": "",
"type": "bytes32[]",
"internalType": "bytes32[]"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getEncryptedCommitment",
Expand All @@ -576,11 +481,6 @@
"type": "tuple",
"internalType": "struct PreConfCommitmentStore.EncrPreConfCommitment",
"components": [
{
"name": "commitmentUsed",
"type": "bool",
"internalType": "bool"
},
{
"name": "commiter",
"type": "address",
Expand Down Expand Up @@ -615,11 +515,6 @@
"type": "tuple",
"internalType": "struct PreConfCommitmentStore.EncrPreConfCommitment",
"components": [
{
"name": "commitmentUsed",
"type": "bool",
"internalType": "bool"
},
{
"name": "commiter",
"type": "address",
Expand Down Expand Up @@ -755,7 +650,7 @@
"internalType": "address"
},
{
"name": "_commitment_dispatch_window",
"name": "_commitmentDispatchWindow",
"type": "uint64",
"internalType": "uint64"
}
Expand Down Expand Up @@ -897,54 +792,6 @@
],
"stateMutability": "view"
},
{
"type": "function",
"name": "providerCommitments",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "providerEncryptedCommitments",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
},
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "providerRegistry",
Expand Down
314 changes: 58 additions & 256 deletions contracts-abi/clients/PreConfCommitmentStore/PreConfCommitmentStore.go

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions contracts/contracts/BidderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ contract BidderRegistry is IBidderRegistry, OwnableUpgradeable, ReentrancyGuardU
BidState memory bidState = BidPayment[commitmentDigest];
require(
bidState.state == State.PreConfirmed,
"The bid was not preconfirmed"
"The bid was not preconfirmed or already processed"
);
uint256 decayedAmt = (bidState.bidAmt *
residualBidPercentAfterDecay *
Expand All @@ -225,8 +225,8 @@ contract BidderRegistry is IBidderRegistry, OwnableUpgradeable, ReentrancyGuardU
bidState.bidAmt -
decayedAmt;

BidPayment[commitmentDigest].state = State.Withdrawn;
BidPayment[commitmentDigest].bidAmt = 0;
// after rewarding the funds, no point to keep bid payment in the mapping
delete BidPayment[commitmentDigest];

emit FundsRewarded(
commitmentDigest,
Expand All @@ -244,12 +244,12 @@ contract BidderRegistry is IBidderRegistry, OwnableUpgradeable, ReentrancyGuardU
*/
function unlockFunds(uint256 window, bytes32 bidID) external nonReentrant onlyPreConfirmationEngine() {
BidState memory bidState = BidPayment[bidID];
require(bidState.state == State.PreConfirmed, "The bid was not preconfirmed");
require(bidState.state == State.PreConfirmed, "The bid was not preconfirmed or already processed");
uint256 amt = bidState.bidAmt;
lockedFunds[bidState.bidder][window] += amt;

BidPayment[bidID].state = State.Withdrawn;
BidPayment[bidID].bidAmt = 0;
// after unlocking the funds, no point to keep bid payment in the mapping
delete BidPayment[bidID];

emit FundsRetrieved(bidID, bidState.bidder, window, amt);
}
Expand Down Expand Up @@ -348,7 +348,7 @@ contract BidderRegistry is IBidderRegistry, OwnableUpgradeable, ReentrancyGuardU
"funds can only be withdrawn after the window is settled"
);
uint256 amount = lockedFunds[bidder][window];
lockedFunds[bidder][window] = 0;
delete lockedFunds[bidder][window];
require(amount > 0, "bidder Amount is zero");

(bool success, ) = bidder.call{value: amount}("");
Expand Down
Loading

0 comments on commit 4b344de

Please sign in to comment.