Skip to content

Commit 5088a1c

Browse files
committed
Add flushtimestamp to verify digest & timestamp.
1 parent 6a60e5d commit 5088a1c

File tree

7 files changed

+26
-4
lines changed

7 files changed

+26
-4
lines changed

cmd/dcrtime/dcrtime.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ func verifyDigests(vd []v2.VerifyDigest) {
443443
d.ChainInformation.ChainTimestamp)
444444
fmt.Printf(" %-16v: %v\n", "Server Timestamp",
445445
d.ServerTimestamp)
446+
fmt.Printf(" %-16v: %v\n", "Flush Timestamp",
447+
d.FlushTimestamp)
446448
fmt.Printf(" %-16v: %v\n", "Merkle Root",
447449
d.ChainInformation.MerkleRoot)
448450
fmt.Printf(" %-16v: %v\n", "TxID",
@@ -498,6 +500,10 @@ func verifyTimestamps(vt []v2.VerifyTimestamp) error {
498500
prefix = ""
499501
}
500502

503+
// Print flush time
504+
fmt.Printf(" %-15v: %v\n", "Flush Timestamp",
505+
t.FlushTimestamp)
506+
501507
// Only print additional info if we are anchored
502508
if t.CollectionInformation.ChainTimestamp == 0 {
503509
continue

dcrtimed/backend/backend.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ type PutResult struct {
5252
ErrorCode uint
5353
}
5454

55-
// TimestampResult is a cooked error returned by the backend.
55+
// TimestampResult is a cooked response returned by the backend.
5656
type TimestampResult struct {
5757
Timestamp int64 // Collection timestamp
58+
FlushTimestamp int64 // Flush timestamp
5859
ErrorCode uint // Overall result
5960
Confirmations *int32 // Tx confirmations
6061
MinConfirmations int32 // Mininum number of confirmations to return timestamp proof
@@ -72,6 +73,7 @@ type GetResult struct {
7273
Confirmations *int32 // Tx confirmations
7374
MinConfirmations int32 // Mininum number of confirmations to return timestamp proof
7475
AnchoredTimestamp int64 // Anchored timestamp
76+
FlushTimestamp int64 // Flush timestamp
7577
Tx chainhash.Hash // Anchor Tx
7678
MerkleRoot [sha256.Size]byte // Merkle root
7779
MerklePath merkle.Branch // Auth path

dcrtimed/backend/filesystem/filesystem.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ func (fs *FileSystem) getTimestamp(timestamp int64) (backend.TimestampResult, er
477477
}
478478

479479
gtme.AnchoredTimestamp = fr.ChainTimestamp
480+
gtme.FlushTimestamp = fr.FlushTimestamp
480481

481482
return gtme, nil
482483
}
@@ -546,6 +547,7 @@ func (fs *FileSystem) getDigest(now time.Time, current *leveldb.DB, digest [sha2
546547
// That pointer better not be nil!
547548
gdme.MerklePath = *merkle.AuthPath(fr.Hashes, &digest)
548549
gdme.Timestamp = fr.ServerTimestamp
550+
gdme.FlushTimestamp = fr.FlushTimestamp
549551

550552
// Override error code during testing
551553
if fs.testing {

dcrtimed/backend/filesystem/filesystem_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ func TestGetDigests(t *testing.T) {
188188
t.Fatalf("server timmestamp should be the directory timestamp, want %d got %d",
189189
timestamp, gr.Timestamp)
190190
}
191+
// Ensure the flush timestamp is set
192+
if gr.ErrorCode == 0 && gr.FlushTimestamp == 0 {
193+
t.Fatalf("expected flush timestamp to be set, got 0")
194+
}
191195
}
192196
}
193197

@@ -446,6 +450,10 @@ func TestGetTimestamp(t *testing.T) {
446450
if len(exists) != count {
447451
t.Fatalf("expected %v exists got %v", count, len(exists))
448452
}
453+
// Ensure flush timestamp is set
454+
if gtme.FlushTimestamp == 0 {
455+
t.Fatalf("expected flush timestamp to be set, got 0")
456+
}
449457
}
450458

451459
func TestPut(t *testing.T) {

dcrtimed/dcrtimed.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ func (d *DcrtimeStore) verifyBatchV2(w http.ResponseWriter, r *http.Request) {
849849
for _, ts := range tsr {
850850
vt := v2.VerifyTimestamp{
851851
ServerTimestamp: ts.Timestamp,
852+
FlushTimestamp: ts.FlushTimestamp,
852853
CollectionInformation: v2.CollectionInformation{
853854
ChainTimestamp: ts.AnchoredTimestamp,
854855
Confirmations: ts.Confirmations,
@@ -913,6 +914,7 @@ func (d *DcrtimeStore) verifyBatchV2(w http.ResponseWriter, r *http.Request) {
913914
vd := v2.VerifyDigest{
914915
Digest: hex.EncodeToString(dr.Digest[:]),
915916
ServerTimestamp: dr.Timestamp,
917+
FlushTimestamp: dr.FlushTimestamp,
916918
ChainInformation: v2.ChainInformation{
917919
Confirmations: dr.Confirmations,
918920
MinConfirmations: dr.MinConfirmations,
@@ -1102,6 +1104,7 @@ func (d *DcrtimeStore) verifyV2(w http.ResponseWriter, r *http.Request) {
11021104
ts := tsr[len(tsr)-1]
11031105
vt := v2.VerifyTimestamp{
11041106
ServerTimestamp: ts.Timestamp,
1107+
FlushTimestamp: ts.FlushTimestamp,
11051108
CollectionInformation: v2.CollectionInformation{
11061109
ChainTimestamp: ts.AnchoredTimestamp,
11071110
Confirmations: ts.Confirmations,
@@ -1167,6 +1170,7 @@ func (d *DcrtimeStore) verifyV2(w http.ResponseWriter, r *http.Request) {
11671170
vd := v2.VerifyDigest{
11681171
Digest: hex.EncodeToString(dr.Digest[:]),
11691172
ServerTimestamp: dr.Timestamp,
1173+
FlushTimestamp: dr.FlushTimestamp,
11701174
ChainInformation: v2.ChainInformation{
11711175
Confirmations: dr.Confirmations,
11721176
MinConfirmations: dr.MinConfirmations,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/decred/dcrd/txscript/v4 v4.1.0
1313
github.com/decred/dcrd/wire v1.6.0
1414
github.com/decred/dcrdata/api/types/v5 v5.0.1
15-
github.com/decred/dcrtime/api/v2 v2.0.0
15+
github.com/decred/dcrtime/api/v2 v2.1.0
1616
github.com/decred/slog v1.2.0
1717
github.com/gorilla/handlers v1.5.1
1818
github.com/gorilla/mux v1.8.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ github.com/decred/dcrdata/semver v1.0.0 h1:DBqYU/x+4LqHq/3r4xKdF6xG5ewktG2KDC+g/
112112
github.com/decred/dcrdata/semver v1.0.0/go.mod h1:z+nQqiAd9fYkHhBLbejysZ2FPHtgkrErWDgMf+JlZWE=
113113
github.com/decred/dcrdata/txhelpers/v4 v4.0.1 h1:jNPPSP5HzE4cfddj5zIJhrIEus/Tvd28Xvl/uVGjrMI=
114114
github.com/decred/dcrdata/txhelpers/v4 v4.0.1/go.mod h1:cUJbgsIzzI42llHDS0nkPlG49vPJ0cW6IZGbfu5sFrA=
115-
github.com/decred/dcrtime/api/v2 v2.0.0 h1:UB2CBvQslooQc22YF6Bqf/yTMwfxva+DOi2s7bEoJ18=
116-
github.com/decred/dcrtime/api/v2 v2.0.0/go.mod h1:WJshmls13ONj+9KaBwvjGIDsg/NDZa7SLWTb2foYhRc=
115+
github.com/decred/dcrtime/api/v2 v2.1.0 h1:zS8VsVsSzfgQvenT4Ta93eC5LGAVVcf8Wl0JXzQJoRk=
116+
github.com/decred/dcrtime/api/v2 v2.1.0/go.mod h1:WJshmls13ONj+9KaBwvjGIDsg/NDZa7SLWTb2foYhRc=
117117
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.3.0 h1:yCxtFqK7X6GvZWQzHXjCwoGCy9YVe3tGEwxCjW5rYQk=
118118
github.com/decred/dcrwallet/rpc/jsonrpc/types v1.3.0/go.mod h1:Xvekb43GtfMiRbyIY4ZJ9Uhd9HRIAcnp46f3q2eIExU=
119119
github.com/decred/go-socks v1.1.0 h1:dnENcc0KIqQo3HSXdgboXAHgqsCIutkqq6ntQjYtm2U=

0 commit comments

Comments
 (0)