diff --git a/go/common/l1_transaction.go b/go/common/l1_transaction.go index 5569da5191..5af4ac1f65 100644 --- a/go/common/l1_transaction.go +++ b/go/common/l1_transaction.go @@ -49,14 +49,29 @@ func (tx *L1TxData) HasSequencerEnclaveID() bool { } func (p *ProcessedL1Data) AddEvent(txType L1TxType, tx *L1TxData) { + eventType := uint8(txType) + + // Find existing event group for i := range p.Events { - if p.Events[i].Type == uint8(txType) { - p.Events[i].Txs = append(p.Events[i].Txs, tx) - return + if p.Events[i].Type != eventType { + continue } + + txHash := tx.Transaction.Hash() + + // check for duplicate transaction + for _, existingTx := range p.Events[i].Txs { + if existingTx.Transaction.Hash() == txHash { + return // Skip duplicate transaction + } + } + + p.Events[i].Txs = append(p.Events[i].Txs, tx) + return } + p.Events = append(p.Events, L1Event{ - Type: uint8(txType), // Convert to uint8 when storing + Type: eventType, Txs: []*L1TxData{tx}, }) } diff --git a/go/enclave/components/rollup_consumer.go b/go/enclave/components/rollup_consumer.go index 934e9876fe..88b19ffcbc 100644 --- a/go/enclave/components/rollup_consumer.go +++ b/go/enclave/components/rollup_consumer.go @@ -126,43 +126,54 @@ func (rc *rollupConsumerImpl) extractAndVerifyRollups(processed *common.Processe rollupTxs := processed.GetEvents(common.RollupTx) rollups := make([]*common.ExtRollup, 0, len(rollupTxs)) - blobs, blobHashes, err := rc.extractBlobsAndHashes(rollupTxs) - if err != nil { - return nil, err - } - + //println("---- START OF ROLLUP CHECK -------") + //println("length of rollupTxs: ", len(rollupTxs)) for i, tx := range rollupTxs { t := rc.MgmtContractLib.DecodeTx(tx.Transaction) if t == nil { continue } + //println("TX HASH: ", tx.Transaction.Hash().Hex()) rollupHashes, ok := t.(*ethadapter.L1RollupHashes) if !ok { continue } + // Only use blobs from this transaction + blobs := tx.Blobs + _, blobHashes, err := ethadapter.MakeSidecar(blobs) + if err != nil { + return nil, fmt.Errorf("could not create blob sidecar and blob hashes. Cause: %w", err) + } + if err := verifyBlobHashes(rollupHashes, blobHashes); err != nil { - rc.logger.Warn(fmt.Sprintf("blob hashes in rollup at index %d do not match the rollup blob hashes. Cause: %s", i, err)) - continue // Blob hashes don't match, skip this rollup + rc.logger.Warn(fmt.Sprintf("blob hashes in rollup at index %d do not match the rollup blob hashes. Cause: %s", i, err), log.NodeIDKey) + continue } + //println("ROLLUP CONSUMER blobs: ", len(blobs)) + //for i, h := range blobHashes { + // println("ROLLUP CONSUMER blob hash: ", h.Hex(), " at index: ", i) + //} + r, err := ethadapter.ReconstructRollup(blobs) if err != nil { - // This is a critical error because we've already verified the blob hashes - // If we can't reconstruct the rollup at this point, something is seriously wrong return nil, fmt.Errorf("could not recreate rollup from blobs. Cause: %w", err) } + //println("Adding rollup to list: ", r.Hash().Hex()) rollups = append(rollups, r) rc.logger.Info("Extracted rollup from block", log.RollupHashKey, r.Hash(), log.BlockHashKey, processed.BlockHeader.Hash()) } if len(rollups) > 1 { - println("HERE") if rollups[0].Hash() == rollups[1].Hash() { - println("ROLLUPS THE SAME") + println("ROLLUPS THE SAME: ", rollups[0].Hash().Hex()) + return []*common.ExtRollup{rollups[0]}, nil + //rc.logger.Crit("DUPLICATE ROLLUP") } + } return rollups, nil } diff --git a/go/enclave/enclave_admin_service.go b/go/enclave/enclave_admin_service.go index afce53a3f5..76599ba04e 100644 --- a/go/enclave/enclave_admin_service.go +++ b/go/enclave/enclave_admin_service.go @@ -136,12 +136,8 @@ func NewEnclaveAdminAPI(config *enclaveconfig.EnclaveConfig, storage storage.Sto return eas } -func (e *enclaveAdminService) AddSequencer(id common.EnclaveID, proof types.Receipt) common.SystemError { - e.mainMutex.Lock() - defer e.mainMutex.Unlock() - +func (e *enclaveAdminService) AddSequencer(id common.EnclaveID, _ types.Receipt) common.SystemError { // todo - use the proof - err := e.storage.StoreNodeType(context.Background(), id, common.BackupSequencer) if err != nil { return responses.ToInternalError(err) @@ -494,6 +490,16 @@ func (e *enclaveAdminService) ingestL1Block(ctx context.Context, br *common.Bloc // Unsure what to do here; block has been stored } + sequencerAddedTxs := processed.GetEvents(common.SequencerAddedTx) + for _, tx := range sequencerAddedTxs { + if tx.HasSequencerEnclaveID() { + err = e.AddSequencer(tx.SequencerEnclaveID, *tx.Receipt) + if err != nil { + e.logger.Crit("Encountered error while adding sequencer enclaveID", log.ErrKey, err) + } + + } + } if ingestion.IsFork() { e.registry.OnL1Reorg(ingestion) err := e.service.OnL1Fork(ctx, ingestion.ChainFork) diff --git a/go/ethadapter/blob.go b/go/ethadapter/blob.go index d16441c71b..c91022be66 100644 --- a/go/ethadapter/blob.go +++ b/go/ethadapter/blob.go @@ -151,5 +151,6 @@ func ReconstructRollup(blobs []*kzg4844.Blob) (*common.ExtRollup, error) { if err := rlp.DecodeBytes(data, &rollup); err != nil { return nil, fmt.Errorf("could not decode rollup bytes. Cause: %w", err) } + return &rollup, nil } diff --git a/go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go b/go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go index d6184cc4d0..8ad754a939 100644 --- a/go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go +++ b/go/ethadapter/mgmtcontractlib/mgmt_contract_lib.go @@ -153,6 +153,9 @@ func (c *contractLibImpl) CreateBlobRollup(t *ethadapter.L1RollupTx) (types.TxDa return nil, fmt.Errorf("failed to make sidecar: %w", err) } + for i, b := range blobHashes { + println("MGMT CONTRACT creating blob with hashes ", b.Hex(), " at index: ", i) + } return &types.BlobTx{ To: *c.addr, Data: data, diff --git a/go/host/enclave/guardian.go b/go/host/enclave/guardian.go index c1d0481ef9..da7900b60d 100644 --- a/go/host/enclave/guardian.go +++ b/go/host/enclave/guardian.go @@ -242,7 +242,8 @@ func (g *Guardian) HandleBatch(batch *common.ExtBatch) { // todo - @matt - does it make sense to use a timeout context? err := g.submitL2Batch(context.Background(), batch) if err != nil { - g.logger.Error("Error submitting batch to enclave", log.ErrKey, err) + // FIXME change back to Error + g.logger.Warn("Error submitting batch to enclave", log.ErrKey, err) } } diff --git a/go/host/l1/blockrepository.go b/go/host/l1/blockrepository.go index 4ecc43374b..363211eb74 100644 --- a/go/host/l1/blockrepository.go +++ b/go/host/l1/blockrepository.go @@ -209,13 +209,12 @@ func (r *Repository) ExtractTenTransactions(block *common.L1Block) (*common.Proc Events: []common.L1Event{}, } - // Fetch all relevant logs for the block logs, err := r.fetchRelevantLogs(block) if err != nil { return nil, err } - // Process each log sequentially, preserving their natural order + // we have to loop through to preserve receipt order for _, l := range logs { txData, err := r.createTransactionData(l.TxHash) if err != nil { @@ -223,24 +222,22 @@ func (r *Repository) ExtractTenTransactions(block *common.L1Block) (*common.Proc continue } - // Categorize logs inline based on their topics switch l.Topics[0] { case crosschain.CrossChainEventID: - r.processCrossChainLogs(l, txData, processed) case crosschain.ValueTransferEventID: r.processValueTransferLogs(l, txData, processed) case crosschain.SequencerEnclaveGrantedEventID: r.processSequencerLogs(l, txData, processed) - r.processDecodedTransaction(txData, processed) // we need to decode the InitialiseSecretTx + r.processManagementContractTx(txData, processed) // we need to decode the InitialiseSecretTx case crosschain.ImportantContractAddressUpdatedID: - r.processDecodedTransaction(txData, processed) + r.processManagementContractTx(txData, processed) + case crosschain.RollupAddedID: + r.processManagementContractTx(txData, processed) case crosschain.NetworkSecretRequestedID: processed.AddEvent(common.SecretRequestTx, txData) case crosschain.NetworkSecretRespondedID: processed.AddEvent(common.SecretResponseTx, txData) - case crosschain.RollupAddedID: - r.processDecodedTransaction(txData, processed) default: r.logger.Warn("Unknown log topic", "topic", l.Topics[0], "txHash", l.TxHash) } @@ -249,7 +246,7 @@ func (r *Repository) ExtractTenTransactions(block *common.L1Block) (*common.Proc return processed, nil } -// fetchRelevantLogs retrieves all logs from relevant contract addresses +// fetchRelevantLogs retrieves all logs from management contract and message bus addresses func (r *Repository) fetchRelevantLogs(block *common.L1Block) ([]types.Log, error) { blkHash := block.Hash() var allAddresses []gethcommon.Address @@ -295,7 +292,6 @@ func (r *Repository) processCrossChainLogs(l types.Log, txData *common.L1TxData, func (r *Repository) processValueTransferLogs(l types.Log, txData *common.L1TxData, processed *common.ProcessedL1Data) { if transfers, err := crosschain.ConvertLogsToValueTransfers([]types.Log{l}, crosschain.ValueTransferEventName, crosschain.MessageBusABI); err == nil { txData.ValueTransfers = transfers - println("VALUE TRANSFER ADDED") processed.AddEvent(common.CrossChainValueTranserTx, txData) } } @@ -304,26 +300,22 @@ func (r *Repository) processValueTransferLogs(l types.Log, txData *common.L1TxDa func (r *Repository) processSequencerLogs(l types.Log, txData *common.L1TxData, processed *common.ProcessedL1Data) { if enclaveID, err := getEnclaveIdFromLog(l); err == nil { txData.SequencerEnclaveID = enclaveID - println("SEQUENCER ADDED TX") processed.AddEvent(common.SequencerAddedTx, txData) } } // processDecodedTransaction handles decoded transaction types -func (r *Repository) processDecodedTransaction(txData *common.L1TxData, processed *common.ProcessedL1Data) { +func (r *Repository) processManagementContractTx(txData *common.L1TxData, processed *common.ProcessedL1Data) { b := processed.BlockHeader if decodedTx := r.mgmtContractLib.DecodeTx(txData.Transaction); decodedTx != nil { switch t := decodedTx.(type) { case *ethadapter.L1InitializeSecretTx: - println("INITIALIZE TX ADDED") processed.AddEvent(common.InitialiseSecretTx, txData) case *ethadapter.L1SetImportantContractsTx: - println("SET IMPORTANT ADDED") processed.AddEvent(common.SetImportantContractsTx, txData) case *ethadapter.L1RollupHashes: if blobs, err := r.blobResolver.FetchBlobs(context.Background(), b, t.BlobHashes); err == nil { txData.Blobs = blobs - println("ROLLUP ADDED") processed.AddEvent(common.RollupTx, txData) } }