Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(altda-client): pass l1BlockNum to proxy GET requests #15

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions op-alt-da/daclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func NewDAClient(url string, verify bool, pc bool) *DAClient {
}

// GetInput returns the input data for the given encoded commitment bytes.
func (c *DAClient) GetInput(ctx context.Context, comm CommitmentData) ([]byte, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/get/0x%x", c.url, comm.Encode()), nil)
func (c *DAClient) GetInput(ctx context.Context, comm CommitmentData, l1BlockNum uint64) ([]byte, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/get/0x%x?l1_block_number=%d", c.url, comm.Encode(), l1BlockNum), nil)
if err != nil {
return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
Expand Down
16 changes: 8 additions & 8 deletions op-alt-da/daclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ func TestDAClientPrecomputed(t *testing.T) {

require.Equal(t, comm, NewKeccak256Commitment(input))

stored, err := client.GetInput(ctx, comm)
stored, err := client.GetInput(ctx, comm, 0)
require.NoError(t, err)

require.Equal(t, input, stored)

// set a bad commitment in the store
require.NoError(t, store.Put(ctx, comm.Encode(), []byte("bad data")))

_, err = client.GetInput(ctx, comm)
_, err = client.GetInput(ctx, comm, 0)
require.ErrorIs(t, err, ErrCommitmentMismatch)

// test not found error
comm = NewKeccak256Commitment(RandomData(rng, 32))
_, err = client.GetInput(ctx, comm)
_, err = client.GetInput(ctx, comm, 0)
require.ErrorIs(t, err, ErrNotFound)

// test storing bad data
Expand All @@ -63,7 +63,7 @@ func TestDAClientPrecomputed(t *testing.T) {
_, err = client.SetInput(ctx, input)
require.Error(t, err)

_, err = client.GetInput(ctx, NewKeccak256Commitment(input))
_, err = client.GetInput(ctx, NewKeccak256Commitment(input), 0)
require.Error(t, err)
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func TestDAClientService(t *testing.T) {

require.Equal(t, comm.String(), NewKeccak256Commitment(input).String())

stored, err := client.GetInput(ctx, comm)
stored, err := client.GetInput(ctx, comm, 0)
require.NoError(t, err)

require.Equal(t, input, stored)
Expand All @@ -105,12 +105,12 @@ func TestDAClientService(t *testing.T) {
require.NoError(t, store.Put(ctx, comm.Encode(), []byte("bad data")))

// assert no error as generic commitments cannot be verified client side
_, err = client.GetInput(ctx, comm)
_, err = client.GetInput(ctx, comm, 0)
require.NoError(t, err)

// test not found error
comm = NewKeccak256Commitment(RandomData(rng, 32))
_, err = client.GetInput(ctx, comm)
_, err = client.GetInput(ctx, comm, 0)
require.ErrorIs(t, err, ErrNotFound)

// test storing bad data
Expand All @@ -122,6 +122,6 @@ func TestDAClientService(t *testing.T) {
_, err = client.SetInput(ctx, input)
require.Error(t, err)

_, err = client.GetInput(ctx, NewKeccak256Commitment(input))
_, err = client.GetInput(ctx, NewKeccak256Commitment(input), 0)
require.Error(t, err)
}
8 changes: 6 additions & 2 deletions op-alt-da/damgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ type L1Fetcher interface {

// DAStorage interface for calling the DA storage server.
type DAStorage interface {
GetInput(ctx context.Context, key CommitmentData) ([]byte, error)
// GetInput returns the input data for the given commitment bytes.
// It passes the l1BlockNum at which the commitment was read (part of a batcher tx),
// in case the validity of the commitment depends on some time component, such as the commitment having
// landed on L1 not too long after having landed on an altda network.
GetInput(ctx context.Context, key CommitmentData, l1BlockNum uint64) ([]byte, error)
SetInput(ctx context.Context, img []byte) (CommitmentData, error)
}

Expand Down Expand Up @@ -208,7 +212,7 @@ func (d *DA) GetInput(ctx context.Context, l1 L1Fetcher, comm CommitmentData, bl
d.log.Info("getting input", "comm", comm, "status", status)

// Fetch the input from the DA storage.
data, err := d.storage.GetInput(ctx, comm)
data, err := d.storage.GetInput(ctx, comm, blockId.Number)
notFound := errors.Is(ErrNotFound, err)
if err != nil && !notFound {
d.log.Error("failed to get preimage", "err", err)
Expand Down
6 changes: 3 additions & 3 deletions op-alt-da/damock.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewMockDAClient(log log.Logger) *MockDAClient {
}
}

func (c *MockDAClient) GetInput(ctx context.Context, key CommitmentData) ([]byte, error) {
func (c *MockDAClient) GetInput(ctx context.Context, key CommitmentData, l1BlockNum uint64) ([]byte, error) {
bytes, err := c.store.Get(key.Encode())
if err != nil {
return nil, ErrNotFound
Expand All @@ -55,12 +55,12 @@ type DAErrFaker struct {
setInputErr error
}

func (f *DAErrFaker) GetInput(ctx context.Context, key CommitmentData) ([]byte, error) {
func (f *DAErrFaker) GetInput(ctx context.Context, key CommitmentData, l1BlockNum uint64) ([]byte, error) {
if err := f.getInputErr; err != nil {
f.getInputErr = nil
return nil, err
}
return f.Client.GetInput(ctx, key)
return f.Client.GetInput(ctx, key, l1BlockNum)
}

func (f *DAErrFaker) SetInput(ctx context.Context, data []byte) (CommitmentData, error) {
Expand Down
6 changes: 3 additions & 3 deletions op-e2e/actions/altda/altda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (a *L2AltDA) ActResolveInput(t helpers.Testing, comm []byte, input []byte,

func (a *L2AltDA) ActResolveLastChallenge(t helpers.Testing) {
// remove derivation byte prefix
input, err := a.storage.GetInput(t.Ctx(), altda.Keccak256Commitment(a.lastComm[1:]))
input, err := a.storage.GetInput(t.Ctx(), altda.Keccak256Commitment(a.lastComm[1:]), 0)
require.NoError(t, err)

a.ActResolveInput(t, a.lastComm, input, a.lastCommBn)
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestAltDA_SequencerStalledMultiChallenges(gt *testing.T) {

// keep track of the related commitment
comm1 := a.lastComm
input1, err := a.storage.GetInput(t.Ctx(), altda.Keccak256Commitment(comm1[1:]))
input1, err := a.storage.GetInput(t.Ctx(), altda.Keccak256Commitment(comm1[1:]), 0)
bn1 := a.lastCommBn
require.NoError(t, err)

Expand Down Expand Up @@ -490,7 +490,7 @@ func TestAltDA_SequencerStalledMultiChallenges(gt *testing.T) {

// keep track of the second commitment
comm2 := a.lastComm
_, err = a.storage.GetInput(t.Ctx(), altda.Keccak256Commitment(comm2[1:]))
_, err = a.storage.GetInput(t.Ctx(), altda.Keccak256Commitment(comm2[1:]), 0)
require.NoError(t, err)
a.lastCommBn = a.miner.L1Chain().CurrentBlock().Number.Uint64()

Expand Down