Skip to content

Commit ad353a2

Browse files
buck54321zquestz
authored andcommitted
add timestamps to waddrmgr.BlockStamp
1 parent 12db43a commit ad353a2

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

headerfs/store.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
"sort"
910
"sync"
11+
"time"
1012

1113
"github.com/gcash/bchd/blockchain"
1214
"github.com/gcash/bchd/chaincfg"
@@ -15,8 +17,6 @@ import (
1517
"github.com/gcash/bchutil/gcs/builder"
1618
"github.com/gcash/bchwallet/waddrmgr"
1719
"github.com/gcash/bchwallet/walletdb"
18-
"sort"
19-
"time"
2020
)
2121

2222
// BlockHeaderStore is an interface that provides an abstraction for a generic
@@ -334,11 +334,11 @@ func (h *blockHeaderStore) RollbackLastBlock() (*waddrmgr.BlockStamp, error) {
334334
// With this height obtained, we'll use it to read the latest header
335335
// from disk, so we can populate our return value which requires the
336336
// prev header hash.
337-
bestHeader, err := h.readHeader(chainTipHeight)
337+
prevHeader, err := h.readHeader(chainTipHeight - 1)
338338
if err != nil {
339339
return nil, err
340340
}
341-
prevHeaderHash := bestHeader.PrevBlock
341+
prevHeaderHash := prevHeader.BlockHash()
342342

343343
// Now that we have the information we need to return from this
344344
// function, we can now truncate the header file, and then use the hash
@@ -351,8 +351,9 @@ func (h *blockHeaderStore) RollbackLastBlock() (*waddrmgr.BlockStamp, error) {
351351
}
352352

353353
return &waddrmgr.BlockStamp{
354-
Height: int32(chainTipHeight) - 1,
355-
Hash: prevHeaderHash,
354+
Height: int32(chainTipHeight) - 1,
355+
Hash: prevHeaderHash,
356+
Timestamp: prevHeader.Timestamp,
356357
}, nil
357358
}
358359

neutrino.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ import (
2020

2121
"github.com/gcash/bchd/addrmgr"
2222
"github.com/gcash/bchd/blockchain"
23+
"github.com/gcash/bchd/btcjson"
2324
"github.com/gcash/bchd/chaincfg"
2425
"github.com/gcash/bchd/chaincfg/chainhash"
2526
"github.com/gcash/bchd/connmgr"
2627
"github.com/gcash/bchd/peer"
28+
"github.com/gcash/bchd/txscript"
2729
"github.com/gcash/bchd/wire"
2830
"github.com/gcash/bchutil"
31+
"github.com/gcash/bchutil/gcs"
32+
"github.com/gcash/bchutil/gcs/builder"
2933
"github.com/gcash/bchwallet/waddrmgr"
3034
"github.com/gcash/bchwallet/walletdb"
35+
"github.com/gcash/neutrino/banman"
3136
"github.com/gcash/neutrino/blockntfns"
3237
"github.com/gcash/neutrino/cache/lru"
3338
"github.com/gcash/neutrino/filterdb"
@@ -920,8 +925,9 @@ func (s *ChainService) BestBlock() (*waddrmgr.BlockStamp, error) {
920925
}
921926

922927
return &waddrmgr.BlockStamp{
923-
Height: int32(bestHeight),
924-
Hash: bestHeader.BlockHash(),
928+
Height: int32(bestHeight),
929+
Hash: bestHeader.BlockHash(),
930+
Timestamp: bestHeader.Timestamp,
925931
}, nil
926932
}
927933

@@ -1116,8 +1122,9 @@ func (s *ChainService) rollBackToHeight(height uint32) (*waddrmgr.BlockStamp, er
11161122
return nil, err
11171123
}
11181124
bs := &waddrmgr.BlockStamp{
1119-
Height: int32(headerHeight),
1120-
Hash: header.BlockHash(),
1125+
Height: int32(headerHeight),
1126+
Hash: header.BlockHash(),
1127+
Timestamp: header.Timestamp,
11211128
}
11221129

11231130
_, regHeight, err := s.RegFilterHeaders.ChainTip()

rescan.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/gcash/bchd/chaincfg"
1414

1515
"github.com/gcash/bchd/btcjson"
16+
"github.com/gcash/bchd/chaincfg"
1617
"github.com/gcash/bchd/chaincfg/chainhash"
1718
"github.com/gcash/bchd/rpcclient"
1819
"github.com/gcash/bchd/txscript"
@@ -523,6 +524,7 @@ func rescan(chain ChainSource, options ...RescanOption) error {
523524
curHeader = header
524525
curStamp.Hash = header.BlockHash()
525526
curStamp.Height++
527+
curStamp.Timestamp = header.Timestamp
526528
}
527529

528530
log.Tracef("Rescan got block %d (%s)", curStamp.Height,

0 commit comments

Comments
 (0)