Skip to content

Commit 2e08b19

Browse files
author
Naohiro Yoshida
committed
support milli timestamp
Signed-off-by: Naohiro Yoshida <[email protected]>
1 parent 65872ea commit 2e08b19

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

module/header.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package module
22

33
import (
44
"fmt"
5+
"github.com/holiman/uint256"
56
"log"
67

78
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
@@ -82,3 +83,11 @@ func (h *Header) Account(path common.Address) (*types.StateAccount, error) {
8283
}
8384
return verifyAccount(target, h.AccountProof, path)
8485
}
86+
87+
func MilliTimestamp(h *types.Header) uint64 {
88+
milliseconds := uint64(0)
89+
if h.MixDigest != (common.Hash{}) {
90+
milliseconds = uint256.NewInt(0).SetBytes32(h.MixDigest[:]).Uint64()
91+
}
92+
return h.Time*1000 + milliseconds
93+
}

module/prover.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (pr *Prover) buildInitialState(dstHeader core.Header) (exported.ClientState
257257
ForkSpecs: GetForkParameters(Network(pr.config.Network)),
258258
}
259259
consensusState := ConsensusState{
260-
Timestamp: header.Time,
260+
Timestamp: MilliTimestamp(header),
261261
PreviousValidatorsHash: makeEpochHash(previousValidators, previousTurnLength),
262262
CurrentValidatorsHash: makeEpochHash(currentValidators, currentTurnLength),
263263
StateRoot: stateRoot.Bytes(),

tests/prover_network_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (ts *ProverNetworkTestSuite) TestSuccessCreateInitialLightClientState() {
9999
consState := s2.(*module.ConsensusState)
100100
ts.Require().Equal(consState.CurrentValidatorsHash, module.MakeEpochHash(cVal, cTurn))
101101
ts.Require().Equal(consState.PreviousValidatorsHash, module.MakeEpochHash(pVal, pTurn))
102-
ts.Require().Equal(consState.Timestamp, header.Time)
102+
ts.Require().Equal(consState.Timestamp, module.MilliTimestamp(header))
103103
storageRoot, err := ts.prover.GetStorageRoot(header)
104104
ts.Require().NoError(err)
105105
ts.Require().Equal(common.BytesToHash(consState.StateRoot), storageRoot)

0 commit comments

Comments
 (0)