Skip to content

Commit 3c89bc6

Browse files
authored
Merge pull request #202 from hyperledger-labs/fix-timestamp-nanosecs
Clarify getTimestampAtHeight returns nanoseconds from unix epoch Signed-off-by: Jun Kimura <[email protected]>
2 parents 9e672af + 0bb0f0f commit 3c89bc6

File tree

8 files changed

+13
-9
lines changed

8 files changed

+13
-9
lines changed

.gas-snapshot

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
IBCTest:testBenchmarkCreateMockClient() (gas: 212200)
1+
IBCTest:testBenchmarkCreateMockClient() (gas: 213924)
22
IBCTest:testBenchmarkRecvPacket() (gas: 152562)
33
IBCTest:testBenchmarkSendPacket() (gas: 85084)
4-
IBCTest:testBenchmarkUpdateMockClient() (gas: 126734)
5-
IBCTest:testConnectionOpenInit() (gas: 494208)
4+
IBCTest:testBenchmarkUpdateMockClient() (gas: 129368)
5+
IBCTest:testConnectionOpenInit() (gas: 495932)
66
IBCTest:testToUint128((uint64,uint64)) (runs: 256, μ: 1051, ~: 1051)

contracts/clients/IBFT2Client.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ contract IBFT2Client is ILightClient {
9191

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

105107
/**

contracts/clients/MockClient.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ contract MockClient is ILightClient {
7474

7575
/**
7676
* @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height.
77+
* The timestamp is nanoseconds since unix epoch.
7778
*/
7879
function getTimestampAtHeight(string calldata clientId, Height.Data calldata height)
7980
external

contracts/core/02-client/ILightClient.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface ILightClient {
1818

1919
/**
2020
* @dev getTimestampAtHeight returns the timestamp of the consensus state at the given height.
21+
* The timestamp is nanoseconds since unix epoch.
2122
*/
2223
function getTimestampAtHeight(string calldata clientId, Height.Data calldata height)
2324
external

contracts/core/04-channel/IBCPacket.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ contract IBCPacket is IBCStore, IIBCPacket {
2121
/**
2222
* @dev sendPacket is called by a module in order to send an IBC packet on a channel.
2323
* The packet sequence generated for the packet to be sent is returned. An error
24-
* is returned if one occurs.
24+
* is returned if one occurs. Also, `timeoutTimestamp` is given in nanoseconds since unix epoch.
2525
*/
2626
function sendPacket(
2727
string calldata sourcePort,

contracts/core/04-channel/IIBCChannel.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface IIBCPacket {
4040
/**
4141
* @dev sendPacket is called by a module in order to send an IBC packet on a channel.
4242
* The packet sequence generated for the packet to be sent is returned. An error
43-
* is returned if one occurs.
43+
* is returned if one occurs. Also, `timeoutTimestamp` is given in nanoseconds since unix epoch.
4444
*/
4545
function sendPacket(
4646
string calldata sourcePort,

pkg/testing/chains.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (chain *Chain) ConstructMockMsgCreateClient(counterparty *Chain) ibchandler
262262
LatestHeight: ibcclient.NewHeightFromBN(counterparty.LastHeader().Number),
263263
}
264264
consensusState := mockclienttypes.ConsensusState{
265-
Timestamp: counterparty.LastHeader().Time,
265+
Timestamp: counterparty.LastHeader().Time * 1e9,
266266
}
267267
clientStateBytes, err := MarshalWithAny(&clientState)
268268
if err != nil {

tests/foundry/src/IBC.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ contract IBCTest is Test {
155155
})
156156
),
157157
consensusStateBytes: wrapAnyMockConsensusState(
158-
IbcLightclientsMockV1ConsensusState.Data({timestamp: uint64(block.timestamp)})
158+
IbcLightclientsMockV1ConsensusState.Data({timestamp: uint64(block.timestamp * 1e9)})
159159
)
160160
})
161161
);
@@ -168,7 +168,7 @@ contract IBCTest is Test {
168168
clientMessage: wrapAnyMockHeader(
169169
IbcLightclientsMockV1Header.Data({
170170
height: Height.Data({revision_number: 0, revision_height: nextRevisionHeight}),
171-
timestamp: uint64(block.timestamp)
171+
timestamp: uint64(block.timestamp * 1e9)
172172
})
173173
)
174174
})

0 commit comments

Comments
 (0)