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

Commit

Permalink
Updates node to pass the published timestamp via rpc.
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Apr 4, 2024
1 parent b279c98 commit bae13c8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
6 changes: 3 additions & 3 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,9 @@ type noOpBidProcessor struct{}
func (noOpBidProcessor) ProcessBid(
_ context.Context,
_ *preconfpb.Bid,
) (chan providerapiv1.BidResponse_Status, error) {
statusC := make(chan providerapiv1.BidResponse_Status, 5)
statusC <- providerapiv1.BidResponse_STATUS_ACCEPTED
) (chan providerapi.ProcessedBidResponse, error) {
statusC := make(chan providerapi.ProcessedBidResponse, 5)
statusC <- providerapi.ProcessedBidResponse{Status: providerapiv1.BidResponse_STATUS_ACCEPTED, PublishedTimestamp: time.Now().UnixMilli()}
close(statusC)

return statusC, nil
Expand Down
7 changes: 4 additions & 3 deletions pkg/preconfirmation/preconfirmation.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
providerapiv1 "github.com/primevprotocol/mev-commit/gen/go/providerapi/v1"
preconfcontract "github.com/primevprotocol/mev-commit/pkg/contracts/preconf"
"github.com/primevprotocol/mev-commit/pkg/p2p"
providerapi "github.com/primevprotocol/mev-commit/pkg/rpc/provider"
signer "github.com/primevprotocol/mev-commit/pkg/signer/preconfsigner"
"github.com/primevprotocol/mev-commit/pkg/topology"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -44,7 +45,7 @@ type BidderStore interface {
}

type BidProcessor interface {
ProcessBid(context.Context, *preconfpb.Bid) (chan providerapiv1.BidResponse_Status, error)
ProcessBid(context.Context, *preconfpb.Bid) (chan providerapi.ProcessedBidResponse, error)
}

func New(
Expand Down Expand Up @@ -221,11 +222,11 @@ func (p *Preconfirmation) handleBid(
case <-ctx.Done():
return ctx.Err()
case st := <-statusC:
switch st {
switch st.Status {
case providerapiv1.BidResponse_STATUS_REJECTED:
return status.Errorf(codes.Internal, "bid rejected")
case providerapiv1.BidResponse_STATUS_ACCEPTED:
preConfirmation, err := p.signer.ConstructPreConfirmation(bid, time.Now().UnixMilli())
preConfirmation, err := p.signer.ConstructPreConfirmation(bid, st.PublishedTimestamp)
if err != nil {
return status.Errorf(codes.Internal, "failed to construct preconfirmation: %v", err)
}
Expand Down
13 changes: 8 additions & 5 deletions pkg/preconfirmation/preconfirmation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/primevprotocol/mev-commit/pkg/p2p"
p2ptest "github.com/primevprotocol/mev-commit/pkg/p2p/testing"
"github.com/primevprotocol/mev-commit/pkg/preconfirmation"
providerapi "github.com/primevprotocol/mev-commit/pkg/rpc/provider"
"github.com/primevprotocol/mev-commit/pkg/topology"
)

Expand Down Expand Up @@ -56,15 +57,16 @@ func (t *testSigner) VerifyPreConfirmation(_ *preconfpb.PreConfirmation) (*commo
}

type testProcessor struct {
status providerapiv1.BidResponse_Status
status providerapiv1.BidResponse_Status
timestamp int64
}

func (t *testProcessor) ProcessBid(
_ context.Context,
_ *preconfpb.Bid,
) (chan providerapiv1.BidResponse_Status, error) {
statusC := make(chan providerapiv1.BidResponse_Status, 1)
statusC <- t.status
) (chan providerapi.ProcessedBidResponse, error) {
statusC := make(chan providerapi.ProcessedBidResponse, 1)
statusC <- providerapi.ProcessedBidResponse{t.status, t.timestamp}

Check failure on line 69 in pkg/preconfirmation/preconfirmation_test.go

View workflow job for this annotation

GitHub Actions / Build and Test

composites: github.com/primevprotocol/mev-commit/pkg/rpc/provider.ProcessedBidResponse struct literal uses unkeyed fields (govet)
return statusC, nil
}

Expand Down Expand Up @@ -132,7 +134,8 @@ func TestPreconfBidSubmission(t *testing.T) {
topo := &testTopo{server}
us := &testBidderStore{}
proc := &testProcessor{
status: providerapiv1.BidResponse_STATUS_ACCEPTED,
status: providerapiv1.BidResponse_STATUS_ACCEPTED,
timestamp: 10,
}
signer := &testSigner{
bid: bid,
Expand Down
20 changes: 13 additions & 7 deletions pkg/rpc/provider/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
type Service struct {
providerapiv1.UnimplementedProviderServer
receiver chan *providerapiv1.Bid
bidsInProcess map[string]func(providerapiv1.BidResponse_Status)
bidsInProcess map[string]func(providerapiv1.BidResponse_Status, int64)
bidsMu sync.Mutex
logger *slog.Logger
owner common.Address
Expand All @@ -33,6 +33,11 @@ type Service struct {
validator *protovalidate.Validator
}

type ProcessedBidResponse struct {
Status providerapiv1.BidResponse_Status
PublishedTimestamp int64
}

type EvmClient interface {
PendingTxns() []evmclient.TxnInfo
CancelTx(ctx context.Context, txHash common.Hash) (common.Hash, error)
Expand All @@ -47,7 +52,7 @@ func NewService(
) *Service {
return &Service{
receiver: make(chan *providerapiv1.Bid),
bidsInProcess: make(map[string]func(providerapiv1.BidResponse_Status)),
bidsInProcess: make(map[string]func(providerapiv1.BidResponse_Status, int64)),
registryContract: registryContract,
owner: owner,
logger: logger,
Expand All @@ -67,7 +72,7 @@ func toString(bid *providerapiv1.Bid) string {
func (s *Service) ProcessBid(
ctx context.Context,
bid *preconfpb.Bid,
) (chan providerapiv1.BidResponse_Status, error) {
) (chan ProcessedBidResponse, error) {
bidMsg := &providerapiv1.Bid{
TxHashes: strings.Split(bid.TxHash, ","),
BidAmount: bid.BidAmount,
Expand All @@ -82,10 +87,11 @@ func (s *Service) ProcessBid(
return nil, err
}

respC := make(chan providerapiv1.BidResponse_Status, 1)
respC := make(chan ProcessedBidResponse, 1)

s.bidsMu.Lock()
s.bidsInProcess[string(bid.Digest)] = func(status providerapiv1.BidResponse_Status) {
respC <- status
s.bidsInProcess[string(bid.Digest)] = func(status providerapiv1.BidResponse_Status, timestamp int64) {
respC <- ProcessedBidResponse{status, timestamp}
close(respC)
}
s.bidsMu.Unlock()
Expand Down Expand Up @@ -150,7 +156,7 @@ func (s *Service) SendProcessedBids(srv providerapiv1.Provider_SendProcessedBids
"bidDigest", hex.EncodeToString(status.BidDigest),
"status", status.Status.String(),
)
callback(status.Status)
callback(status.Status, status.DecayPublishedTimestamp)
if status.Status == providerapiv1.BidResponse_STATUS_ACCEPTED {
s.metrics.BidsAcceptedByProviderCount.Inc()
} else {
Expand Down
4 changes: 2 additions & 2 deletions pkg/rpc/provider/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ func TestBidHandling(t *testing.T) {

select {
case resp := <-respC:
if resp != tc.status {
t.Fatalf("expected status to be %v, got %v", tc.status, resp)
if resp.Status != tc.status {
t.Fatalf("expected status to be %v, got %v", tc.status, resp.Status)
}
if tc.noStatus {
t.Fatalf("expected no status, got %v", resp)
Expand Down

0 comments on commit bae13c8

Please sign in to comment.