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

Commit

Permalink
Updated preconfimration struct field names.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Oct 13, 2023
1 parent c56269e commit 2dfef6a
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 94 deletions.
96 changes: 48 additions & 48 deletions gen/go/rpc/searcherapi/v1/searcherapi.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions pkg/preconfirmation/preconfirmation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ func TestPreconfBidSubmission(t *testing.T) {
TxnHash: "test",
BidAmt: big.NewInt(10),
BlockNumber: big.NewInt(10),
BidHash: []byte("test"),
Digest: []byte("test"),
Signature: []byte("test"),
}

preConfirmation := &preconfsigner.PreConfirmation{
Bid: *bid,
PreconfirmationDigest: []byte("test"),
PreConfirmationSignature: []byte("test"),
Bid: *bid,
Digest: []byte("test"),
Signature: []byte("test"),
}

svc := p2ptest.New(
Expand Down Expand Up @@ -127,13 +127,13 @@ func TestPreconfBidSubmission(t *testing.T) {
t.Fatal(err)
}

resp := <-respC
commitment := <-respC

if string(resp.PreconfirmationDigest) != "test" {
if string(commitment.Digest) != "test" {
t.Fatalf("data hash is not equal to test")
}

if string(resp.PreConfirmationSignature) != "test" {
if string(commitment.Signature) != "test" {
t.Fatalf("preConfirmation signature is not equal to test")
}
})
Expand Down
6 changes: 3 additions & 3 deletions pkg/rpc/builder/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (s *Service) ProcessBid(
) (chan builderapiv1.BidResponse_Status, error) {
respC := make(chan builderapiv1.BidResponse_Status, 1)
s.bidsMu.Lock()
s.bidsInProcess[string(bid.BidHash)] = func(status builderapiv1.BidResponse_Status) {
s.bidsInProcess[string(bid.Digest)] = func(status builderapiv1.BidResponse_Status) {
respC <- status
close(respC)
}
Expand All @@ -40,7 +40,7 @@ func (s *Service) ProcessBid(
select {
case <-ctx.Done():
s.bidsMu.Lock()
delete(s.bidsInProcess, string(bid.BidHash))
delete(s.bidsInProcess, string(bid.Digest))
s.bidsMu.Unlock()

s.logger.Error("context cancelled for sending bid", "err", ctx.Err())
Expand All @@ -49,7 +49,7 @@ func (s *Service) ProcessBid(
TxnHash: bid.TxnHash,
BidAmt: bid.BidAmt.Int64(),
BlockNumber: bid.BlockNumber.Int64(),
BidHash: bid.BidHash,
BidHash: bid.Digest,
}:
}
s.logger.Info("sent bid to builder node", "bid", bid)
Expand Down
23 changes: 15 additions & 8 deletions pkg/rpc/searcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package searcherapi

import (
"context"
"encoding/hex"
"log/slog"
"math/big"

Expand Down Expand Up @@ -35,7 +36,7 @@ func (s *Service) SendBid(
respC, err := s.sender.SendBid(
srv.Context(),
bid.TxnHash,
big.NewInt(bid.BidAmt),
big.NewInt(bid.Amount),
big.NewInt(bid.BlockNumber),
)
if err != nil {
Expand All @@ -46,14 +47,14 @@ func (s *Service) SendBid(
for resp := range respC {
err := srv.Send(&searcherapiv1.PreConfirmation{
Bid: &searcherapiv1.Bid{
TxnHash: resp.TxnHash,
BidAmt: resp.BidAmt.Int64(),
BlockNumber: resp.BlockNumber.Int64(),
TxnHash: resp.Bid.TxnHash,
Amount: resp.Bid.BidAmt.Int64(),
BlockNumber: resp.Bid.BlockNumber.Int64(),
},
BidHash: resp.BidHash,
Signature: resp.Signature,
PreconfirmationDigest: resp.PreconfirmationDigest,
PreConfirmationSignature: resp.PreConfirmationSignature,
BidHash: hex.EncodeToString(resp.Bid.Digest),
BidSignature: hex.EncodeToString(resp.Bid.Signature),
Digest: hex.EncodeToString(resp.Digest),
Signature: hex.EncodeToString(resp.Signature),
})
if err != nil {
s.logger.Error("error sending preConfirmation", "err", err)
Expand All @@ -63,3 +64,9 @@ func (s *Service) SendBid(

return nil
}

func HexEncode(src []byte) string {
dst := make([]byte, hex.EncodedLen(len(src)))
hex.Encode(dst, src)
return string(dst)
}
4 changes: 2 additions & 2 deletions pkg/signer/preconfsigner/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (p *privateKeySigner) BidOriginator(bid *Bid) (*common.Address, *ecdsa.Publ
return nil, nil, err
}

pubkey, err := crypto.SigToPub(bid.BidHash, bid.Signature)
pubkey, err := crypto.SigToPub(bid.Digest, bid.Signature)
if err != nil {
return nil, nil, err
}
Expand All @@ -31,7 +31,7 @@ func (p *privateKeySigner) PreConfirmationOriginator(
return nil, nil, err
}

pubkey, err := crypto.SigToPub(c.PreconfirmationDigest, c.PreConfirmationSignature)
pubkey, err := crypto.SigToPub(c.Digest, c.Signature)
if err != nil {
return nil, nil, err
}
Expand Down
42 changes: 21 additions & 21 deletions pkg/signer/preconfsigner/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ var (
// Adds blocknumber for pre-conf bid - Will need to manage
// how to reciever acts on a bid / TTL is the blocknumber
type Bid struct {
TxnHash string `json:"txnHash"`
BidAmt *big.Int `json:"bid"`
BlockNumber *big.Int `json:"blocknumber"`
TxnHash string `json:"txn_hash"`
BidAmt *big.Int `json:"bid_amt"`
BlockNumber *big.Int `json:"block_number"`

BidHash []byte `json:"bidhash"` // TODO(@ckaritk): name better
Signature []byte `json:"signature"`
Digest []byte `json:"bid_digest"` // TODO(@ckaritk): name better
Signature []byte `json:"bid_signature"`
}

type PreConfirmation struct {
Bid
Bid Bid `json:"bid"`

PreconfirmationDigest []byte `json:"preconfirmation_digest"` // TODO(@ckaritk): name better
PreConfirmationSignature []byte `json:"preConfirmation_signature"`
Digest []byte `json:"digest"` // TODO(@ckaritk): name better
Signature []byte `json:"signature"`
}

type Signer interface {
Expand Down Expand Up @@ -83,7 +83,7 @@ func (p *privateKeySigner) ConstructSignedBid(
return nil, err
}

bid.BidHash = bidHash
bid.Digest = bidHash
bid.Signature = sig

return bid, nil
Expand All @@ -103,7 +103,7 @@ func (p *privateKeySigner) ConstructPreConfirmation(bid *Bid) (*PreConfirmation,
bid.TxnHash,
bid.BidAmt,
bid.BlockNumber,
bid.BidHash,
bid.Digest,
bid.Signature,
)

Expand All @@ -117,26 +117,26 @@ func (p *privateKeySigner) ConstructPreConfirmation(bid *Bid) (*PreConfirmation,
return nil, err
}

preConfirmation.PreconfirmationDigest = preconfirmationDigest
preConfirmation.PreConfirmationSignature = sig
preConfirmation.Digest = preconfirmationDigest
preConfirmation.Signature = sig

return preConfirmation, nil
}

func (p *privateKeySigner) VerifyBid(bid *Bid) (*common.Address, error) {
if bid.BidHash == nil || bid.Signature == nil {
if bid.Digest == nil || bid.Signature == nil {
return nil, ErrMissingHashSignature
}

return eipVerify(
constructBidPayload(bid.TxnHash, bid.BidAmt, bid.BlockNumber),
bid.BidHash,
bid.Digest,
bid.Signature,
)
}

func (p *privateKeySigner) VerifyPreConfirmation(c *PreConfirmation) (*common.Address, error) {
if c.PreconfirmationDigest == nil || c.PreConfirmationSignature == nil {
if c.Digest == nil || c.Signature == nil {
return nil, ErrMissingHashSignature
}

Expand All @@ -146,14 +146,14 @@ func (p *privateKeySigner) VerifyPreConfirmation(c *PreConfirmation) (*common.Ad
}

internalPayload := constructPreConfirmationPayload(
c.TxnHash,
c.BidAmt,
c.BlockNumber,
c.BidHash,
c.Signature,
c.Bid.TxnHash,
c.Bid.BidAmt,
c.Bid.BlockNumber,
c.Bid.Digest,
c.Bid.Signature,
)

return eipVerify(internalPayload, c.PreconfirmationDigest, c.PreConfirmationSignature)
return eipVerify(internalPayload, c.Digest, c.Signature)
}

func eipVerify(
Expand Down
Loading

0 comments on commit 2dfef6a

Please sign in to comment.