Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
fix(prover): fix guardian prover database key (#522)
Browse files Browse the repository at this point in the history
Co-authored-by: maskpp <maskpp266@gmail.com>
Co-authored-by: David <david@taiko.xyz>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent 9ce7d96 commit 35eee7c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
7 changes: 4 additions & 3 deletions prover/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var (
blockKeyPrefix = "block-"
blockKeyPrefix = "block"
separator = "++"
)

Expand All @@ -21,12 +21,13 @@ type SignedBlockData struct {
}

// BuildBlockKey will build a block key for a signed block
func BuildBlockKey(blockTimestamp uint64) []byte {
func BuildBlockKey(blockTimestamp uint64, blockNumber uint64) []byte {
return bytes.Join(
[][]byte{
[]byte(blockKeyPrefix),
[]byte(strconv.Itoa(int(blockTimestamp))),
}, []byte{})
[]byte(strconv.Itoa(int(blockNumber))),
}, []byte(separator))
}

// BuildBlockValue will build a block value for a signed block
Expand Down
2 changes: 1 addition & 1 deletion prover/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func Test_BuildBlockKey(t *testing.T) {
assert.Equal(t, []byte("block-1"), BuildBlockKey(1))
assert.Equal(t, []byte("block++1++300"), BuildBlockKey(1, 300))
}

func Test_BuildBlockValue(t *testing.T) {
Expand Down
12 changes: 4 additions & 8 deletions prover/guardian_prover_sender/guardian_prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,13 @@ func (s *GuardianProverBlockSender) SignAndSendBlock(ctx context.Context, blockI
return err
}

if err := s.db.Put(
db.BuildBlockKey(header.Time),
return s.db.Put(
db.BuildBlockKey(header.Time, header.Number.Uint64()),
db.BuildBlockValue(header.Hash().Bytes(),
signed,
blockID,
),
); err != nil {
return err
}

return nil
)
}

// sendSignedBlockReq is the actual method that sends the signed block to the health check server.
Expand Down Expand Up @@ -173,7 +169,7 @@ func (s *GuardianProverBlockSender) sign(ctx context.Context, blockID *big.Int)
return nil, nil, err
}

exists, err := s.db.Has(db.BuildBlockKey(header.Time))
exists, err := s.db.Has(db.BuildBlockKey(header.Time, header.Number.Uint64()))
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 35eee7c

Please sign in to comment.