Skip to content

Commit

Permalink
refactor: allow sender to be configurable per bridge. (#47)
Browse files Browse the repository at this point in the history
allow sender to be configurable per bridge.

closes #46
  • Loading branch information
mycodecrafting authored Sep 27, 2024
1 parent f397898 commit 10b0c8c
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
{
"bridgeAddress": "astria1xnlvg0rle2u6auane79t4p27g8hxnj36ja960z",
"senderAddress": "0x0000000000000000000000000000000000000000",
"startHeight": 1,
"assetDenom": "transfer/channel-1/usdc",
"assetPrecision": 6,
Expand All @@ -39,7 +40,6 @@
}
}
],
"astriaBridgeSenderAddress": "0x0000000000000000000000000000000000000000",
"astriaFeeCollectors": {
"1": "0xaC21B97d35Bf75A7dAb16f35b111a50e78A72F30"
},
Expand Down
6 changes: 2 additions & 4 deletions grpc/execution/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type ExecutionServiceServerV1Alpha2 struct {

bridgeAddresses map[string]*params.AstriaBridgeAddressConfig // astria bridge addess to config for that bridge account
bridgeAllowedAssets map[string]struct{} // a set of allowed asset IDs structs are left empty
bridgeSenderAddress common.Address // address from which AstriaBridgeableERC20 contracts are called

nextFeeRecipient common.Address // Fee recipient for the next block
}
Expand Down Expand Up @@ -113,7 +112,7 @@ func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) (*ExecutionServiceServ
nativeBridgeSeen = true
}

if cfg.Erc20Asset != nil && bc.Config().AstriaBridgeSenderAddress == (common.Address{}) {
if cfg.Erc20Asset != nil && cfg.SenderAddress == (common.Address{}) {
return nil, errors.New("astria bridge sender address must be set for bridged ERC20 assets")
}

Expand Down Expand Up @@ -149,7 +148,6 @@ func NewExecutionServiceServerV1Alpha2(eth *eth.Ethereum) (*ExecutionServiceServ
bc: bc,
bridgeAddresses: bridgeAddresses,
bridgeAllowedAssets: bridgeAllowedAssets,
bridgeSenderAddress: bc.Config().AstriaBridgeSenderAddress,
nextFeeRecipient: nextFeeRecipient,
}, nil
}
Expand Down Expand Up @@ -264,7 +262,7 @@ func (s *ExecutionServiceServerV1Alpha2) ExecuteBlock(ctx context.Context, req *

txsToProcess := types.Transactions{}
for _, tx := range req.Transactions {
unmarshalledTx, err := validateAndUnmarshalSequencerTx(height, tx, s.bridgeAddresses, s.bridgeAllowedAssets, s.bridgeSenderAddress)
unmarshalledTx, err := validateAndUnmarshalSequencerTx(height, tx, s.bridgeAddresses, s.bridgeAllowedAssets)
if err != nil {
log.Debug("failed to validate sequencer tx, ignoring", "tx", tx, "err", err)
continue
Expand Down
1 change: 1 addition & 0 deletions grpc/execution/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block, stri
config.AstriaBridgeAddressConfigs = []params.AstriaBridgeAddressConfig{
{
BridgeAddress: bech32mBridgeAddress,
SenderAddress: common.Address{},
StartHeight: 2,
AssetDenom: "nria",
AssetPrecision: 18,
Expand Down
5 changes: 2 additions & 3 deletions grpc/execution/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ func validateAndUnmarshalSequencerTx(
tx *sequencerblockv1alpha1.RollupData,
bridgeAddresses map[string]*params.AstriaBridgeAddressConfig,
bridgeAllowedAssets map[string]struct{},
bridgeSenderAddress common.Address,
) (*types.Transaction, error) {
if deposit := tx.GetDeposit(); deposit != nil {
bridgeAddress := deposit.BridgeAddress.GetBech32M()
Expand Down Expand Up @@ -63,7 +62,7 @@ func validateAndUnmarshalSequencerTx(
}

txdata := types.DepositTx{
From: bridgeSenderAddress,
From: bac.SenderAddress,
Value: new(big.Int), // don't need to set this, as we aren't minting the native asset
// mints cost ~14k gas, however this can vary based on existing storage, so we add a little extra as buffer.
//
Expand All @@ -79,7 +78,7 @@ func validateAndUnmarshalSequencerTx(
}

txdata := types.DepositTx{
From: bridgeSenderAddress,
From: bac.SenderAddress,
To: &recipient,
Value: amount,
Gas: 0,
Expand Down
2 changes: 1 addition & 1 deletion grpc/execution/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func TestSequenceTxValidation(t *testing.T) {

for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
_, err := validateAndUnmarshalSequencerTx(2, test.sequencerTx, serviceV1Alpha1.bridgeAddresses, serviceV1Alpha1.bridgeAllowedAssets, common.Address{})
_, err := validateAndUnmarshalSequencerTx(2, test.sequencerTx, serviceV1Alpha1.bridgeAddresses, serviceV1Alpha1.bridgeAllowedAssets)
if test.wantErr == "" && err == nil {
return
}
Expand Down
2 changes: 1 addition & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ type ChainConfig struct {
AstriaCelestiaInitialHeight uint64 `json:"astriaCelestiaInitialHeight"`
AstriaCelestiaHeightVariance uint64 `json:"astriaCelestiaHeightVariance,omitempty"`
AstriaBridgeAddressConfigs []AstriaBridgeAddressConfig `json:"astriaBridgeAddresses,omitempty"`
AstriaBridgeSenderAddress common.Address `json:"astriaBridgeSenderAddress,omitempty"`
AstriaFeeCollectors map[uint32]common.Address `json:"astriaFeeCollectors"`
AstriaEIP1559Params *AstriaEIP1559Params `json:"astriaEIP1559Params,omitempty"`
}
Expand Down Expand Up @@ -1055,6 +1054,7 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp uint64) Rules

type AstriaBridgeAddressConfig struct {
BridgeAddress string `json:"bridgeAddress"`
SenderAddress common.Address `json:"senderAddress,omitempty"`
StartHeight uint32 `json:"startHeight"`
AssetDenom string `json:"assetDenom"`
AssetPrecision uint16 `json:"assetPrecision"`
Expand Down

0 comments on commit 10b0c8c

Please sign in to comment.