Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zjg555543 committed Jan 3, 2024
1 parent 138b0e2 commit cff691e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/jsonrpc"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/mitchellh/mapstructure"
"github.com/spf13/viper"
"github.com/urfave/cli/v2"
Expand All @@ -28,6 +29,8 @@ type Config struct {
Log log.Config
RPC jsonrpc.Config
L1 L1Config

SignSequenceAddress common.Address `mapstructure:"SignSequenceAddress"`
}

// L1Config is a struct that defines L1 contract and service settings
Expand Down
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// DefaultValues is the default configuration
const DefaultValues = `
PrivateKey = {Path = "/pk/test-member.keystore", Password = "testonly"}
SignSequenceAddress = ""
[L1]
WsURL = "ws://127.0.0.1:8546"
Expand Down
10 changes: 8 additions & 2 deletions services/datacom/datacom.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/0xPolygon/cdk-data-availability/synchronizer"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/ethereum/go-ethereum/common"
"github.com/jackc/pgx/v4"
)

Expand All @@ -20,6 +22,8 @@ type DataComEndpoints struct {
txMan jsonrpc.DBTxManager
privateKey *ecdsa.PrivateKey
sequencerTracker *synchronizer.SequencerTracker

signSequenceAddress common.Address
}

// NewDataComEndpoints returns DataComEndpoints
Expand All @@ -39,12 +43,14 @@ func NewDataComEndpoints(
func (d *DataComEndpoints) SignSequence(signedSequence sequence.SignedSequence) (interface{}, types.Error) {
// Verify that the request comes from the sequencer
sender, err := signedSequence.Signer()
if err != nil {
if err != nil || sender.Cmp(common.Address{}) == 0 {
return "0x0", types.NewRPCError(types.DefaultErrorCode, "failed to verify sender")
}
if sender != d.sequencerTracker.GetAddr() {
if sender != d.sequencerTracker.GetAddr() && sender != d.signSequenceAddress {
return "0x0", types.NewRPCError(types.DefaultErrorCode, "unauthorized")
}
log.Infof("SignSequence, signedSequence sender: %v, sequencerTracker:%v, signSequenceAddress:%s", sender.String(), d.sequencerTracker.GetAddr().String(), d.signSequenceAddress.String())

// Store off-chain data by hash (hash(L2Data): L2Data)
_, err = d.txMan.NewDbTxScope(d.db, func(ctx context.Context, dbTx pgx.Tx) (interface{}, types.Error) {
err := d.db.StoreOffChainData(ctx, signedSequence.Sequence.OffChainData(), dbTx)
Expand Down
1 change: 1 addition & 0 deletions test/config/test.da.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PrivateKey = {Path = "/pk/test-member.keystore", Password = "testonly"}
SignSequenceAddress = ""

[L1]
WsURL = "ws://x1-mock-l1-network:8546"
Expand Down

0 comments on commit cff691e

Please sign in to comment.