From 04b228041fc44f2b1cfd4152a9f262929acbbe43 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Mon, 9 Dec 2024 16:09:55 +0200 Subject: [PATCH 1/2] Removal of balance. --- go/enclave/components/batch_executor.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/go/enclave/components/batch_executor.go b/go/enclave/components/batch_executor.go index 562635c35..4db567659 100644 --- a/go/enclave/components/batch_executor.go +++ b/go/enclave/components/batch_executor.go @@ -26,6 +26,7 @@ import ( gethcommon "github.com/ethereum/go-ethereum/common" smt "github.com/FantasyJony/openzeppelin-merkle-tree-go/standard_merkle_tree" + "github.com/ethereum/go-ethereum/core/tracing" "github.com/ethereum/go-ethereum/core/types" gethlog "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" @@ -142,6 +143,10 @@ func (executor *batchExecutor) ComputeBatch(ctx context.Context, ec *BatchExecut return nil, ErrNoTransactionsToProcess } + if err := executor.postProcessState(ec); err != nil { + return nil, fmt.Errorf("failed to post process state. Cause: %w", err) + } + return executor.execResult(ec) } @@ -335,6 +340,20 @@ func (executor *batchExecutor) execRegisteredCallbacks(ec *BatchExecutionContext return nil } +func (executor *batchExecutor) postProcessState(ec *BatchExecutionContext) error { + receipts := ec.batchTxResults.Receipts() + valueTransferMessages, err := executor.crossChainProcessors.Local.ExtractOutboundTransfers(ec.ctx, receipts) + if err != nil { + return fmt.Errorf("could not extract outbound transfers. Cause: %w", err) + } + + for _, msg := range valueTransferMessages { + ec.stateDB.SubBalance(*executor.crossChainProcessors.Local.GetBusAddress(), uint256.MustFromBig(msg.Amount), tracing.BalanceChangeUnspecified) + } + + return nil +} + func (executor *batchExecutor) execOnBlockEndTx(ec *BatchExecutionContext) error { onBlockTx, err := executor.systemContracts.CreateOnBatchEndTransaction(ec.ctx, ec.stateDB, ec.batchTxResults) if err != nil && !errors.Is(err, system.ErrNoTransactions) { From f26562b8f582c470ac8ba4c3b424ed2caadd0f14 Mon Sep 17 00:00:00 2001 From: StefanIliev545 Date: Mon, 9 Dec 2024 16:18:11 +0200 Subject: [PATCH 2/2] Clarifying comments. --- go/enclave/components/batch_executor.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go/enclave/components/batch_executor.go b/go/enclave/components/batch_executor.go index 4db567659..db45ad762 100644 --- a/go/enclave/components/batch_executor.go +++ b/go/enclave/components/batch_executor.go @@ -143,6 +143,7 @@ func (executor *batchExecutor) ComputeBatch(ctx context.Context, ec *BatchExecut return nil, ErrNoTransactionsToProcess } + // Step 5: burn native value on the message bus according to what has been bridged out to the L1. if err := executor.postProcessState(ec); err != nil { return nil, fmt.Errorf("failed to post process state. Cause: %w", err) } @@ -340,6 +341,7 @@ func (executor *batchExecutor) execRegisteredCallbacks(ec *BatchExecutionContext return nil } +// postProcessState - Function for applying post processing, which currently is removing the value from the balance of the message bus contract. func (executor *batchExecutor) postProcessState(ec *BatchExecutionContext) error { receipts := ec.batchTxResults.Receipts() valueTransferMessages, err := executor.crossChainProcessors.Local.ExtractOutboundTransfers(ec.ctx, receipts)