Skip to content

Commit

Permalink
Merge pull request #202 from hyperledger-labs/fix-timestamp-nanosecs
Browse files Browse the repository at this point in the history
Clarify getTimestampAtHeight returns nanoseconds from unix epoch

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Aug 30, 2023
2 parents 9e672af + 0bb0f0f commit 3c89bc6
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
IBCTest:testBenchmarkCreateMockClient() (gas: 212200)
IBCTest:testBenchmarkCreateMockClient() (gas: 213924)
IBCTest:testBenchmarkRecvPacket() (gas: 152562)
IBCTest:testBenchmarkSendPacket() (gas: 85084)
IBCTest:testBenchmarkUpdateMockClient() (gas: 126734)
IBCTest:testConnectionOpenInit() (gas: 494208)
IBCTest:testBenchmarkUpdateMockClient() (gas: 129368)
IBCTest:testConnectionOpenInit() (gas: 495932)
IBCTest:testToUint128((uint64,uint64)) (runs: 256, μ: 1051, ~: 1051)
4 changes: 3 additions & 1 deletion contracts/clients/IBFT2Client.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ contract IBFT2Client is ILightClient {

/**
* @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height.
* The timestamp is nanoseconds since unix epoch.
*/
function getTimestampAtHeight(string calldata clientId, Height.Data calldata height)
external
Expand All @@ -99,7 +100,8 @@ contract IBFT2Client is ILightClient {
returns (uint64, bool)
{
ConsensusState.Data storage consensusState = consensusStates[clientId][height.toUint128()];
return (consensusState.timestamp, consensusState.timestamp != 0);
// ConsensState.timestamp is seconds since unix epoch, so need to convert it to nanoseconds
return (consensusState.timestamp * 1e9, consensusState.timestamp != 0);
}

/**
Expand Down
1 change: 1 addition & 0 deletions contracts/clients/MockClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ contract MockClient is ILightClient {

/**
* @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height.
* The timestamp is nanoseconds since unix epoch.
*/
function getTimestampAtHeight(string calldata clientId, Height.Data calldata height)
external
Expand Down
1 change: 1 addition & 0 deletions contracts/core/02-client/ILightClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface ILightClient {

/**
* @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height.
* The timestamp is nanoseconds since unix epoch.
*/
function getTimestampAtHeight(string calldata clientId, Height.Data calldata height)
external
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/04-channel/IBCPacket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract IBCPacket is IBCStore, IIBCPacket {
/**
* @dev sendPacket is called by a module in order to send an IBC packet on a channel.
* The packet sequence generated for the packet to be sent is returned. An error
* is returned if one occurs.
* is returned if one occurs. Also, `timeoutTimestamp` is given in nanoseconds since unix epoch.
*/
function sendPacket(
string calldata sourcePort,
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/04-channel/IIBCChannel.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface IIBCPacket {
/**
* @dev sendPacket is called by a module in order to send an IBC packet on a channel.
* The packet sequence generated for the packet to be sent is returned. An error
* is returned if one occurs.
* is returned if one occurs. Also, `timeoutTimestamp` is given in nanoseconds since unix epoch.
*/
function sendPacket(
string calldata sourcePort,
Expand Down
2 changes: 1 addition & 1 deletion pkg/testing/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (chain *Chain) ConstructMockMsgCreateClient(counterparty *Chain) ibchandler
LatestHeight: ibcclient.NewHeightFromBN(counterparty.LastHeader().Number),
}
consensusState := mockclienttypes.ConsensusState{
Timestamp: counterparty.LastHeader().Time,
Timestamp: counterparty.LastHeader().Time * 1e9,
}
clientStateBytes, err := MarshalWithAny(&clientState)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions tests/foundry/src/IBC.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ contract IBCTest is Test {
})
),
consensusStateBytes: wrapAnyMockConsensusState(
IbcLightclientsMockV1ConsensusState.Data({timestamp: uint64(block.timestamp)})
IbcLightclientsMockV1ConsensusState.Data({timestamp: uint64(block.timestamp * 1e9)})
)
})
);
Expand All @@ -168,7 +168,7 @@ contract IBCTest is Test {
clientMessage: wrapAnyMockHeader(
IbcLightclientsMockV1Header.Data({
height: Height.Data({revision_number: 0, revision_height: nextRevisionHeight}),
timestamp: uint64(block.timestamp)
timestamp: uint64(block.timestamp * 1e9)
})
)
})
Expand Down

0 comments on commit 3c89bc6

Please sign in to comment.