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

new clock implementation and tests #1

Merged
merged 18 commits into from
Dec 22, 2023
Merged

new clock implementation and tests #1

merged 18 commits into from
Dec 22, 2023

Conversation

stephenctw
Copy link
Contributor

@stephenctw stephenctw commented Oct 2, 2023

  • Implement real clock
  • Achieve 100% function test coverage, excluding machine related ones
  • Add forge fmt --check and forge test to CI
  • Update lua node to keep track of block time after fastforwarding
  • (lua-node) Add two idle players, which will be eliminated by honest player calling eliminateMatchByTimeout

@stephenctw stephenctw requested a review from GCdePaula October 3, 2023 11:13
@stephenctw stephenctw self-assigned this Oct 3, 2023
@stephenctw
Copy link
Contributor Author

I failed to re-enable Match.t.sol because of this issue.

@stephenctw stephenctw added the enhancement New feature or request label Oct 3, 2023
@stephenctw
Copy link
Contributor Author

@GCdePaula I made some changes based on our discussion awhile ago. But I don't think I've covered everything. Could you submit your comments/reviews so I can double check?

Copy link
Collaborator

@GCdePaula GCdePaula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work! I've left a few comments.

// Dummy
Time.Duration constant COMMITMENT_EFFORT = Time.Duration.wrap(0);
Time.Duration constant CENSORSHIP_TOLERANCE = Time.Duration.wrap(60 * 5);
Time.Duration constant MATCH_EFFORT = Time.Duration.wrap(60 * 2);

// 4-level tournament
uint64 constant LEVELS = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to update this comment.

Copy link
Contributor Author

@stephenctw stephenctw Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, what should it be updated to?

@@ -241,9 +262,42 @@ function HonestStrategy:_react_tournament(state, tournament)
end
end

for _, match in ipairs(tournament.matches) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue is that this would only run at the tournaments the player is on.

I propose a different approach. Let's separate the two logics. The player only plays the tournaments and matches. Separate from this, we have a garbage collector, which will scan all the tournaments recursively, calling timeout on all matches.

}
Time.Duration _allowance =
_timeLeft.add(ArbitrationConstants.MATCH_EFFORT);
// TODO: do we need this cap check?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need it.

);

_clockOne.addValidatorEffort(Time.ZERO_DURATION);
_clockOne.deduct(_clockTwo.timeSinceTimeout());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this. I believe both clocks are running on step in the leaf match. I think if we deduct, we'll be subtracting it twice.

I think we need to pause it too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so a simple setPaused() should do it here.

/// - if the tournament is finished
/// - the contested parent commitment
/// - the dangling commitment
function innerTournamentWinner()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a mental TODO on how to deal with tournaments where nobody won.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides no one joining, all claims can also time out!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to be able to communicate to the caller:

  • Tournament not finished;
  • Tournament finished, no one won (parent can delete parent match)
  • Tournament finished, here's the winner.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's open an issue for this. We need to change this function, and also the caller of this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#7

} else {
maximumEnforceableDelay = Time.currentTime().add(_allowance);
}
// TODO: do we need this cap check?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need this check :/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the caller should make sure of that instead? I'm not sure.

return true
elseif m1.block_number > m2.block_number then
return false
function CommitmentClock:display(block_time)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the __tostring metamethod!

assert(handle)

local ret
local str = handle:read()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you read everything instead with *a? Might simplify this loop.

@stephenctw stephenctw requested a review from GCdePaula December 15, 2023 12:05
Copy link
Collaborator

@GCdePaula GCdePaula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work :)

/// - if the tournament is finished
/// - the contested parent commitment
/// - the dangling commitment
function innerTournamentWinner()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides no one joining, all claims can also time out!

/// - if the tournament is finished
/// - the contested parent commitment
/// - the dangling commitment
function innerTournamentWinner()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to be able to communicate to the caller:

  • Tournament not finished;
  • Tournament finished, no one won (parent can delete parent match)
  • Tournament finished, here's the winner.

/// - if the tournament is finished
/// - the contested parent commitment
/// - the dangling commitment
function innerTournamentWinner()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's open an issue for this. We need to change this function, and also the caller of this function.

@stephenctw stephenctw merged commit 8819b03 into main Dec 22, 2023
1 check passed
@GCdePaula GCdePaula deleted the feature/clock branch March 23, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants