Skip to content

Commit

Permalink
rename commitment mode (#151)
Browse files Browse the repository at this point in the history
* rename

* restore go.mod and go.sum

---------

Co-authored-by: Ubuntu <[email protected]>
  • Loading branch information
bxue-l2 and Ubuntu authored Sep 25, 2024
1 parent 3f4f2ba commit 6c1e020
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
16 changes: 8 additions & 8 deletions commitments/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ type CommitmentMeta struct {
type CommitmentMode string

const (
OptimismGeneric CommitmentMode = "optimism_keccak256"
OptimismAltDA CommitmentMode = "optimism_generic"
OptimismKeccak CommitmentMode = "optimism_keccak256"
OptimismGeneric CommitmentMode = "optimism_generic"
SimpleCommitmentMode CommitmentMode = "simple"
)

func StringToCommitmentMode(s string) (CommitmentMode, error) {
switch s {
case string(OptimismKeccak):
return OptimismKeccak, nil
case string(OptimismGeneric):
return OptimismGeneric, nil
case string(OptimismAltDA):
return OptimismAltDA, nil
case string(SimpleCommitmentMode):
return SimpleCommitmentMode, nil
default:
Expand All @@ -48,10 +48,10 @@ func StringToDecodedCommitment(key string, c CommitmentMode) ([]byte, error) {
}

switch c {
case OptimismGeneric: // [op_type, ...]
case OptimismKeccak: // [op_type, ...]
return b[1:], nil

case OptimismAltDA: // [op_type, da_provider, cert_version, ...]
case OptimismGeneric: // [op_type, da_provider, cert_version, ...]
return b[3:], nil

case SimpleCommitmentMode: // [cert_version, ...]
Expand All @@ -64,10 +64,10 @@ func StringToDecodedCommitment(key string, c CommitmentMode) ([]byte, error) {

func EncodeCommitment(b []byte, c CommitmentMode) ([]byte, error) {
switch c {
case OptimismGeneric:
case OptimismKeccak:
return Keccak256Commitment(b).Encode(), nil

case OptimismAltDA:
case OptimismGeneric:
certCommit := NewV0CertCommitment(b).Encode()
svcCommit := EigenDASvcCommitment(certCommit).Encode()
altDACommit := NewGenericCommitment(svcCommit).Encode()
Expand Down
2 changes: 1 addition & 1 deletion e2e/optimism_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func TestOptimismKeccak256Commitment(gt *testing.T) {
require.Equal(t, 1, stat.Reads)
}

func TestOptimismAltDACommitment(gt *testing.T) {
func TestOptimismGenericCommitment(gt *testing.T) {
if !runIntegrationTests && !runTestnetIntegrationTests {
gt.Skip("Skipping test as INTEGRATION or TESTNET env var not set")
}
Expand Down
8 changes: 4 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,16 @@ func ReadCommitmentMode(r *http.Request) (commitments.CommitmentMode, error) {

switch decodedCommit[0] {
case byte(commitments.GenericCommitmentType):
return commitments.OptimismAltDA, nil
return commitments.OptimismGeneric, nil

case byte(commitments.Keccak256CommitmentType):
return commitments.OptimismGeneric, nil
return commitments.OptimismKeccak, nil

default:
return commitments.SimpleCommitmentMode, fmt.Errorf("unknown commit byte prefix")
}
}
return commitments.OptimismAltDA, nil
return commitments.OptimismGeneric, nil
}

func ReadCommitmentVersion(r *http.Request, mode commitments.CommitmentMode) (byte, error) {
Expand All @@ -364,7 +364,7 @@ func ReadCommitmentVersion(r *http.Request, mode commitments.CommitmentMode) (by
return 0, fmt.Errorf("commitment is too short")
}

if mode == commitments.OptimismAltDA || mode == commitments.SimpleCommitmentMode {
if mode == commitments.OptimismGeneric || mode == commitments.SimpleCommitmentMode {
return decodedCommit[2], nil
}

Expand Down
8 changes: 4 additions & 4 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestGetHandler(t *testing.T) {
expectedCode: http.StatusOK,
expectedBody: testCommitStr,
expectError: false,
expectedCommitmentMeta: commitments.CommitmentMeta{Mode: commitments.OptimismGeneric, CertVersion: 0},
expectedCommitmentMeta: commitments.CommitmentMeta{Mode: commitments.OptimismKeccak, CertVersion: 0},
},
{
name: "Failure - OP Alt-DA Internal Server Error",
Expand All @@ -118,7 +118,7 @@ func TestGetHandler(t *testing.T) {
expectedCode: http.StatusOK,
expectedBody: testCommitStr,
expectError: false,
expectedCommitmentMeta: commitments.CommitmentMeta{Mode: commitments.OptimismAltDA, CertVersion: 0},
expectedCommitmentMeta: commitments.CommitmentMeta{Mode: commitments.OptimismGeneric, CertVersion: 0},
},
}

Expand Down Expand Up @@ -232,7 +232,7 @@ func TestPutHandler(t *testing.T) {
expectedCode: http.StatusOK,
expectedBody: opGenericPrefixStr + testCommitStr,
expectError: false,
expectedCommitmentMeta: commitments.CommitmentMeta{Mode: commitments.OptimismAltDA, CertVersion: 0},
expectedCommitmentMeta: commitments.CommitmentMeta{Mode: commitments.OptimismGeneric, CertVersion: 0},
},
{
name: "Success OP Mode Keccak256",
Expand All @@ -244,7 +244,7 @@ func TestPutHandler(t *testing.T) {
expectedCode: http.StatusOK,
expectedBody: opKeccakPrefix + testCommitStr,
expectError: false,
expectedCommitmentMeta: commitments.CommitmentMeta{Mode: commitments.OptimismGeneric, CertVersion: 0},
expectedCommitmentMeta: commitments.CommitmentMeta{Mode: commitments.OptimismKeccak, CertVersion: 0},
},
{
name: "Success Simple Commitment Mode",
Expand Down
8 changes: 4 additions & 4 deletions store/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewRouter(eigenda KeyGeneratedStore, s3 PrecomputedKeyStore, l log.Logger,
// Get ... fetches a value from a storage backend based on the (commitment mode, type)
func (r *Router) Get(ctx context.Context, key []byte, cm commitments.CommitmentMode) ([]byte, error) {
switch cm {
case commitments.OptimismGeneric:
case commitments.OptimismKeccak:

if r.s3 == nil {
return nil, errors.New("expected S3 backend for OP keccak256 commitment type, but none configured")
Expand All @@ -70,7 +70,7 @@ func (r *Router) Get(ctx context.Context, key []byte, cm commitments.CommitmentM
}
return value, nil

case commitments.SimpleCommitmentMode, commitments.OptimismAltDA:
case commitments.SimpleCommitmentMode, commitments.OptimismGeneric:
if r.eigenda == nil {
return nil, errors.New("expected EigenDA backend for DA commitment type, but none configured")
}
Expand Down Expand Up @@ -121,9 +121,9 @@ func (r *Router) Put(ctx context.Context, cm commitments.CommitmentMode, key, va
var err error

switch cm {
case commitments.OptimismGeneric: // caching and fallbacks are unsupported for this commitment mode
case commitments.OptimismKeccak: // caching and fallbacks are unsupported for this commitment mode
return r.putWithKey(ctx, key, value)
case commitments.OptimismAltDA, commitments.SimpleCommitmentMode:
case commitments.OptimismGeneric, commitments.SimpleCommitmentMode:
commit, err = r.putWithoutKey(ctx, value)
default:
return nil, fmt.Errorf("unknown commitment mode")
Expand Down

0 comments on commit 6c1e020

Please sign in to comment.