Skip to content

Commit

Permalink
remove console.logs
Browse files Browse the repository at this point in the history
  • Loading branch information
apenzk committed Mar 2, 2025
1 parent 046667a commit 9dae1c7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 80 deletions.
23 changes: 0 additions & 23 deletions protocol-units/settlement/mcr/contracts/src/settlement/MCR.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,9 @@ contract MCR is Initializable, BaseSettlement, MCRStorage, IMCR {
function TrySetCommitmentFirstSeenAt(uint256 height, bytes32 commitment, uint256 timestamp) internal {
if (commitmentFirstSeenAt[height][commitment] != 0) {
// do not set if already set
console.log("[TrySetCommitmentFirstSeenAt] commitment first seen at is already set");
return;
} else if (timestamp == 0) {
// no need to set if timestamp is 0. This if may be redundant though.
console.log("[TrySetCommitmentFirstSeenAt] timestamp is 0");
return;
}
commitmentFirstSeenAt[height][commitment] = timestamp;
Expand Down Expand Up @@ -391,15 +389,12 @@ contract MCR is Initializable, BaseSettlement, MCRStorage, IMCR {
// Award points to postconfirmer
if (!isWithinPostconfirmerPrivilegeDuration(superBlockCommitment)) {
// if we are outside the privilege window, for the postconfirmer reward anyone who postconfirms
console.log("[postconfirmSuperBlockCommitment] privilege window is over");
postconfirmerRewardPoints[currentAcceptingEpoch][attester] += 1;
} else {
// if we are within the privilege window, only award points to the postconfirmer
// TODO optimization: even if the height has been volunteer postconfirmed we need to allow that that postconfirmer gets rewards,
// TODO otherwise weak postconfirmers may could get played (rich volunteer postconfirmers pay the fees and poor postconfirmers never get any reward)
// TODO but check if this is really required game theoretically.
console.log("[postconfirmSuperBlockCommitment] current Postconfirmer is %s", getPostconfirmer());
console.log("[postconfirmSuperBlockCommitment] attester is %s", attester);
if (getPostconfirmer() == attester) {
postconfirmerRewardPoints[currentAcceptingEpoch][attester] += 1;
}
Expand All @@ -426,17 +421,12 @@ contract MCR is Initializable, BaseSettlement, MCRStorage, IMCR {
uint256 acceptingEpoch = getAcceptingEpoch();
address[] memory attesters = getStakedAttestersForAcceptingEpoch();

console.log("[rollOverEpoch] Attesters length at epoch %s is %s", acceptingEpoch, attesters.length);
// reward
for (uint256 i = 0; i < attesters.length; i++) {
if (attesterRewardPoints[acceptingEpoch][attesters[i]] > 0) {
// TODO: make this configurable and set it on instance creation
uint256 reward = attesterRewardPoints[acceptingEpoch][attesters[i]] * rewardPerAttestationPoint * getAttesterStakeForAcceptingEpoch(attesters[i]);
// the staking contract is the custodian
console.log("[rollOverEpoch] Rewarding attester %s with %s", attesters[i], reward);
console.log("[rollOverEpoch] Staking contract is %s", address(stakingContract));
console.log("[rollOverEpoch] Move token address is %s", moveTokenAddress);
console.log("[rollOverEpoch] msg.sender is %s", msg.sender);
// rewards are currently paid out from the mcr domain
stakingContract.rewardFromDomain(attesters[i], reward, moveTokenAddress);
// TODO : check if we really have to keep attesterRewardPoints per epoch, or whether we could simply delete the points here for a given attester.
Expand All @@ -445,10 +435,6 @@ contract MCR is Initializable, BaseSettlement, MCRStorage, IMCR {
// Add postconfirmation rewards
if (postconfirmerRewardPoints[acceptingEpoch][attesters[i]] > 0) {
uint256 reward = postconfirmerRewardPoints[acceptingEpoch][attesters[i]] * rewardPerPostconfirmationPoint * getAttesterStakeForAcceptingEpoch(attesters[i]);
console.log("[rollOverEpoch] Rewarding postconfirmer %s with %s", attesters[i], reward);
console.log("[rollOverEpoch] Staking contract is %s", address(stakingContract));
console.log("[rollOverEpoch] Move token address is %s", moveTokenAddress);
console.log("[rollOverEpoch] msg.sender is %s", msg.sender);
stakingContract.rewardFromDomain(attesters[i], reward, moveTokenAddress);
// TODO : check if we really have to keep postconfirmerRewardPoints per epoch, or whether we could simply delete the points here for a given postconfirmer.
// TODO also the postconfirmer list is super short. typically for a given height only the postconfirmer and at most the postconfirmer and a volunteer postconfirmer.
Expand All @@ -463,14 +449,10 @@ contract MCR is Initializable, BaseSettlement, MCRStorage, IMCR {
/// @dev The postconfirmer's privilege window is the time period when only the postconfirmer will get rewarded for postconfirmation
function isWithinPostconfirmerPrivilegeDuration(SuperBlockCommitment memory superBlockCommitment) public view returns (bool) {
if (getCommitmentFirstSeenAt(superBlockCommitment) == 0) {
console.log("[isWithinPostconfirmerPrivilegeDuration] timestamp is not set for this commitment");
return false;
}
// based on the first timestamp for the commitment we can determine if the postconfirmer has been live sufficiently recently
// use getCommitmentFirstSeenAt, and the mappings
console.log("[isWithinPostconfirmerPrivilegeDuration] getCommitmentFirstSeenAt", getCommitmentFirstSeenAt(superBlockCommitment));
console.log("[isWithinPostconfirmerPrivilegeDuration] getMinCommitmentAgeForPostconfirmation", getMinCommitmentAgeForPostconfirmation());
console.log("[isWithinPostconfirmerPrivilegeDuration] getPostconfirmerPrivilegeDuration", getPostconfirmerPrivilegeDuration());
if (getCommitmentFirstSeenAt(superBlockCommitment)
+ getMinCommitmentAgeForPostconfirmation()
+ getPostconfirmerPrivilegeDuration()
Expand All @@ -484,7 +466,6 @@ contract MCR is Initializable, BaseSettlement, MCRStorage, IMCR {
/// @dev Moreover, due to the leadingBlockTolerance, the assigned epoch for a height could be ahead of the actual epoch.
/// @dev solution is to move to the next epoch and count votes there
function attemptPostconfirmOrRollover(uint256 superBlockHeight) internal returns (bool) {
console.log("[attemptPostconfirmOrRollover] attempting postconfirm or rollover at superblock height %s", superBlockHeight);
uint256 superBlockEpoch = superBlockHeightAssignedEpoch[superBlockHeight];
if (getLastPostconfirmedSuperBlockHeight() == 0) {
console.log("[attemptPostconfirmOrRollover] genesis");
Expand All @@ -510,7 +491,6 @@ contract MCR is Initializable, BaseSettlement, MCRStorage, IMCR {
while (getAcceptingEpoch() < superBlockEpoch) {
// TODO only permit rollover after some liveness criteria for the postconfirmer, as this is related to the reward model (rollovers should be rewarded)
rollOverEpoch();
console.log("[attemptPostconfirmOrRollover] rolled over epoch to %s", getAcceptingEpoch());
}

// TODO only permit postconfirmation after some liveness criteria for the postconfirmer, as this is related to the reward model (postconfirmation should be rewarded)
Expand Down Expand Up @@ -541,7 +521,6 @@ contract MCR is Initializable, BaseSettlement, MCRStorage, IMCR {

_postconfirmSuperBlockCommitment(superBlockCommitment, msg.sender);
successfulPostconfirmation = true;
console.log("[attemptPostconfirmOrRollover] successful postconfirmation at height %s", superBlockHeight);

// TODO: for rewards we have to run through all the attesters, as we need to acknowledge that they get rewards.

Expand All @@ -555,10 +534,8 @@ contract MCR is Initializable, BaseSettlement, MCRStorage, IMCR {
// we rollover the epoch to give the next attesters a chance
if (!successfulPostconfirmation && getPresentEpoch() > getAcceptingEpoch()) {
rollOverEpoch();
console.log("[attemptPostconfirmOrRollover] rolled over to epoch", getAcceptingEpoch());
return true; // we have to retry the postconfirmation at the next epoch again
}
console.log("[attemptPostconfirmOrRollover] no successful postconfirmation");
return false;
}

Expand Down
57 changes: 0 additions & 57 deletions protocol-units/settlement/mcr/contracts/test/settlement/MCR.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ contract MCRTest is Test, IMCR {

// Helper function to setup genesis with 1 attester and their stake
function setupGenesisWithOneAttester(uint256 stakeAmount) internal returns (address attester) {
console.log("[setupGenesisWithOneAttester] This is domain:", address(mcr));

moveToken.mint(address(mcr), stakeAmount*100); // MCR needs tokens to pay rewards
// MCR needs to approve staking contract to spend its tokens
vm.prank(address(mcr));
Expand All @@ -134,7 +132,6 @@ contract MCRTest is Test, IMCR {
address[] memory custodians = new address[](1);
custodians[0] = address(moveToken);
staking.registerDomain(epochDuration, custodians);
console.log("[setupGenesisWithThreeAttesters] Registered domain with epochDuration ", staking.getEpochDuration(address(mcr)));

// TODO this seems odd that we need to do this here.. check for correctnes of this approach
mcr.grantRole(mcr.DEFAULT_ADMIN_ROLE(), address(mcr));
Expand All @@ -143,7 +140,6 @@ contract MCRTest is Test, IMCR {
// vm.warp(3*epochDuration);

// End genesis ceremony
console.log("[setupGenesisWithThreeAttesters] Ending genesis ceremony");
vm.prank(address(mcr));
mcr.acceptGenesisCeremony();

Expand All @@ -159,7 +155,6 @@ contract MCRTest is Test, IMCR {
uint256 bobStakeAmount,
uint256 carolStakeAmount
) internal returns (address alice, address bob, address carol) {
console.log("[setupGenesisWithThreeAttesters] This is domain:", address(mcr));
uint256 totalStakeAmount = aliceStakeAmount + bobStakeAmount + carolStakeAmount;

moveToken.mint(address(mcr), totalStakeAmount*100); // MCR needs tokens to pay rewards
Expand Down Expand Up @@ -193,22 +188,6 @@ contract MCRTest is Test, IMCR {
staking.stake(address(mcr), moveToken, carolStakeAmount);

// Verify stakes
string memory stakeInfo = string.concat(
"[setupGenesisWithThreeAttesters] A/B/C/total stake: ",
Strings.toString(mcr.getStakeForAcceptingEpoch(address(moveToken), alice)), "/",
Strings.toString(mcr.getStakeForAcceptingEpoch(address(moveToken), bob)), "/",
Strings.toString(mcr.getStakeForAcceptingEpoch(address(moveToken), carol)), "/",
Strings.toString(mcr.getTotalStakeForAcceptingEpoch())
);
string memory balanceInfo = string.concat(
"[setupGenesisWithThreeAttesters] A/B/C/total balance: ",
Strings.toString(moveToken.balanceOf(alice)), "/",
Strings.toString(moveToken.balanceOf(bob)), "/",
Strings.toString(moveToken.balanceOf(carol)), "/",
Strings.toString(moveToken.totalSupply())
);
console.log(stakeInfo);
console.log(balanceInfo);
assertEq(mcr.getStakeForAcceptingEpoch(address(moveToken), alice), aliceStakeAmount, "Alice's stake not correct");
assertEq(mcr.getStakeForAcceptingEpoch(address(moveToken), bob), bobStakeAmount, "Bob's stake not correct");
assertEq(mcr.getStakeForAcceptingEpoch(address(moveToken), carol), carolStakeAmount, "Carol's stake not correct");
Expand All @@ -219,7 +198,6 @@ contract MCRTest is Test, IMCR {
address[] memory custodians = new address[](1);
custodians[0] = address(moveToken);
staking.registerDomain(epochDuration, custodians);
console.log("[setupGenesisWithThreeAttesters] Registered domain with epochDuration ", staking.getEpochDuration(address(mcr)));

// TODO this seems odd that we need to do this here.. check for correctnes of this approach
mcr.grantRole(mcr.DEFAULT_ADMIN_ROLE(), address(mcr));
Expand All @@ -228,7 +206,6 @@ contract MCRTest is Test, IMCR {
// vm.warp(3*epochDuration);

// End genesis ceremony
console.log("[setupGenesisWithThreeAttesters] Ending genesis ceremony");
vm.prank(address(mcr));
mcr.acceptGenesisCeremony();

Expand All @@ -237,16 +214,6 @@ contract MCRTest is Test, IMCR {
assertEq(mcr.getStakeForAcceptingEpoch(address(moveToken), bob), bobStakeAmount, "Bob's stake not correct");
assertEq(mcr.getStakeForAcceptingEpoch(address(moveToken), carol), carolStakeAmount, "Carol's stake not correct");
assertEq(mcr.getTotalStakeForAcceptingEpoch(), totalStakeAmount, "Total stake not correct");

console.log("================================================");
console.log("[setupGenesisWithThreeAttesters] moveToken address:", address(moveToken));
console.log("[setupGenesisWithThreeAttesters] staking address:", address(staking));
console.log("[setupGenesisWithThreeAttesters] mcr address:", address(mcr));
console.log("================================================");
console.log("[setupGenesisWithThreeAttesters] alice address:", alice);
console.log("[setupGenesisWithThreeAttesters] bob address:", bob);
console.log("[setupGenesisWithThreeAttesters] carol address:", carol);
console.log("================================================");
}

/// @notice Helper function to setup a new signer with staking
Expand Down Expand Up @@ -294,14 +261,6 @@ contract MCRTest is Test, IMCR {
}

uint256 supermajorityStake = 2 * (honestStake + dishonestStake) / 3 + 1;
// create the string to print for the console log
// string memory logString = string.concat(
// "have honest stake ( supermajority stake ) / dishonest stake / total stake = ",
// Strings.toString(honestStake), "( ", Strings.toString(supermajorityStake), " ) / ",
// Strings.toString(dishonestStake), " / ", Strings.toString(honestStake + dishonestStake)
// );
// console.log(logString);

return honestStake >= supermajorityStake;
}

Expand Down Expand Up @@ -746,14 +705,11 @@ contract MCRTest is Test, IMCR {

// Warp to next epoch
vm.warp(2*epochDuration);
console.log("- - - - - warp to epoch 2 - - - - -");
assertEq(mcr.getPresentEpoch(), 2, "Present epoch should be 2");
assertEq(mcr.getAcceptingEpoch(), 1, "Accepting epoch should be 1");

console.log("- - - - - rollover to epoch 2 - - - - -");
vm.prank(alice);
mcr.postconfirmSuperBlocksAndRollover();
console.log("- - - - - done rollover - - - - -");
assertEq(mcr.getAcceptingEpoch(), 2, "Accepting epoch should be 2");

assertEq(mcr.getStakeForAcceptingEpoch(address(moveToken), carol), 1, "Carol's stake should already be active");
Expand All @@ -765,7 +721,6 @@ contract MCRTest is Test, IMCR {
mcr.submitSuperBlockCommitment(commitment);

// perform postconfirmation
console.log("- - - - - postconfirm height 1 - - - - -");
vm.prank(carol);
mcr.postconfirmSuperBlocksAndRollover();
assertEq(mcr.getLastPostconfirmedSuperBlockHeight(), 1, "Last postconfirmed superblock height should be 1, as supermajority was reached (2/2 > threshold)");
Expand Down Expand Up @@ -797,7 +752,6 @@ contract MCRTest is Test, IMCR {
assertEq(mcr.getLastPostconfirmedSuperBlockHeight(), 0, "Immediate postconfirmation should fail.");

vm.warp(block.timestamp + minAge); // note that time starts at 1, not 0
console.log("time now is", block.timestamp);
// Now postconfirmation should succeed
vm.prank(alice);
mcr.postconfirmSuperBlocksAndRollover();
Expand All @@ -822,9 +776,6 @@ contract MCRTest is Test, IMCR {

// Test at an postconfirmer term boundary
vm.warp(postconfirmerDuration);
console.log("current time", block.timestamp);
console.log("postconfirmerDuration", postconfirmerDuration);
console.log("epochTime", epochDuration);
assertEq(mcr.getPostconfirmerStartTime(), postconfirmerDuration, "Postconfirmer term should start at (3) time postconfirmerDuration");

// Test at an postconfirmer term boundary
Expand Down Expand Up @@ -953,15 +904,12 @@ contract MCRTest is Test, IMCR {
uint256 bobInitialBalance = moveToken.balanceOf(bob);
// set the max postconfirmer non-reactivity time to 1/4 epochDuration
mcr.setPostconfirmerPrivilegeDuration(epochDuration/4);
console.log("postconfirmer privilege window", mcr.getPostconfirmerPrivilegeDuration());

vm.prank(alice);
mcr.submitSuperBlockCommitment(makeHonestCommitment(1));
// check that the first seen timestamp is set
console.log("commitment first seen at", mcr.getCommitmentFirstSeenAt(makeHonestCommitment(1)));
assertGt(mcr.getCommitmentFirstSeenAt(makeHonestCommitment(1)), 0, "Commitment first seen at should be set");

console.log("postconfirmer", mcr.getPostconfirmer());
assertEq(mcr.getPostconfirmer(), bob, "Bob should be the postconfirmer but its not");
assertEq(mcr.isWithinPostconfirmerPrivilegeDuration(makeHonestCommitment(1)), true, "Postconfirmer should be live");

Expand Down Expand Up @@ -999,9 +947,6 @@ contract MCRTest is Test, IMCR {
vm.prank(alice);
mcr.submitSuperBlockCommitment(makeHonestCommitment(1));

console.log("length of staked attesters", mcr.getStakedAttestersForAcceptingEpoch().length);
console.log("postconfirmer", mcr.getPostconfirmer());

assertEq(mcr.getPostconfirmer(), alice, "Alice should be the postconfirmer since it is the only staked attester.");
assertEq(mcr.isWithinPostconfirmerPrivilegeDuration(makeHonestCommitment(1)), true, "Postconfirmer should be live");

Expand Down Expand Up @@ -1043,8 +988,6 @@ contract MCRTest is Test, IMCR {
uint256 thisPostconfirmerPriviledgeWindow = epochDuration/100;
mcr.setPostconfirmerPrivilegeDuration(thisPostconfirmerPriviledgeWindow);
assertEq(mcr.getPostconfirmerPrivilegeDuration(), thisPostconfirmerPriviledgeWindow, "Max postconfirmer non-reactivity time should be 1/100 epochDuration");
console.log("getPostconfirmerPrivilegeDuration", mcr.getPostconfirmerPrivilegeDuration());
console.log("thisPostconfirmerDuration", thisPostconfirmerDuration);
assertGt(thisPostconfirmerDuration, thisPostconfirmerPriviledgeWindow, "Postconfirmer term should be greater than thisPostconfirmerPriviledgeWindow");

vm.prank(alice);
Expand Down

0 comments on commit 9dae1c7

Please sign in to comment.