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

evm & voyager fixes #3402

Merged
merged 5 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 3 additions & 13 deletions evm/contracts/clients/CometblsClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ library CometblsClientLib {
uint64 trustingPeriod,
uint64 currentTime
) internal pure returns (bool) {
return currentTime > (headerTime + trustingPeriod);
return uint256(currentTime)
> (uint256(headerTime) + uint256(trustingPeriod));
}

function encodeMemory(
Expand Down Expand Up @@ -216,11 +217,6 @@ contract CometblsClient is
}
clientStates[clientId] = clientState;
consensusStates[clientId][clientState.latestHeight] = consensusState;
// Normalize to nanosecond because ibc-go recvPacket expects nanos...
processedMoments[clientId][clientState.latestHeight] = ProcessedMoment({
timestamp: block.timestamp * 1e9,
height: block.number
});
return ConsensusStateUpdate({
clientStateCommitment: clientState.commit(),
consensusStateCommitment: consensusState.commit(),
Expand Down Expand Up @@ -316,7 +312,6 @@ contract CometblsClient is
}

uint64 maxClockDrift = currentTime + clientState.maxClockDrift;

if (untrustedTimestamp >= maxClockDrift) {
revert CometblsClientLib.ErrMaxClockDriftExceeded();
}
Expand Down Expand Up @@ -378,15 +373,10 @@ contract CometblsClient is
consensusState.nextValidatorsHash =
header.signedHeader.nextValidatorsHash;

ProcessedMoment storage processed =
processedMoments[clientId][header.trustedHeight];
processed.timestamp = block.timestamp * 1e9;
processed.height = block.number;

return ConsensusStateUpdate({
clientStateCommitment: clientState.commit(),
consensusStateCommitment: consensusState.commit(),
height: header.trustedHeight
height: untrustedHeightNumber
});
}

Expand Down
2 changes: 1 addition & 1 deletion evm/tests/src/02-client/CometblsClient.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ contract CometblsClientTest is Test {
expectedConsensusStateCommitment,
"Consensus state commitment mismatch"
);
assertEq(update.height, 100, "Height mismatch");
assertEq(update.height, 101, "Height mismatch");
}

function verifyMembership(
Expand Down
3 changes: 3 additions & 0 deletions voyager/modules/consensus/cometbls/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ impl ConsensusModuleServer for Module {
let unbonding_period =
u64::try_from(params.unbonding_time.clone().unwrap().seconds).unwrap() * 1_000_000_000;

// Avoid low unbonding period preventing relayer from submitting slightly old headers
let unbonding_period = unbonding_period.max(3 * 24 * 3600 * 1_000_000_000);

Ok(serde_json::to_value(ClientState {
chain_id: cometbls_light_client_types::ChainId::from_string(self.chain_id.to_string())
.unwrap(),
Expand Down
Loading