Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Total TX query fix #1992

Closed
wants to merge 13 commits into from
17 changes: 17 additions & 0 deletions go/enclave/components/batch_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (executor *batchExecutor) filterTransactionsWithSufficientFunds(ctx context
block, _ := executor.storage.FetchBlock(ctx, context.BlockPtr)

for _, tx := range context.Transactions {
fmt.Printf("Tx from context hash: %s\n", tx.Hash().Hex())
sender, err := core.GetAuthenticatedSender(context.ChainConfig.ChainID.Int64(), tx)
if err != nil {
executor.logger.Error("Unable to extract sender for tx. Should not happen at this point.", log.TxKey, tx.Hash(), log.ErrKey, err)
Expand Down Expand Up @@ -193,6 +194,10 @@ func (executor *batchExecutor) ComputeBatch(ctx context.Context, context *BatchE
}

syntheticTransactions := append(xchainTxs, freeTransactions...)
fmt.Printf("Number of synthetic transactions: %d\n", int64(len(syntheticTransactions)))
for _, xTx := range syntheticTransactions {
fmt.Printf("Syntheic tx hash: %s\n", xTx.Tx.Hash().Hex())
}

// fromTxIndex - Here we start from the 0 index. This will be the same for a validator.
successfulTxs, excludedTxs, txReceipts, createdContracts, err := executor.processTransactions(ctx, batch, 0, transactionsToProcess, stateDB, context.ChainConfig, false)
Expand All @@ -210,6 +215,9 @@ func (executor *batchExecutor) ComputeBatch(ctx context.Context, context *BatchE
if err = executor.verifyInboundCrossChainTransactions(syntheticTransactions, ccSuccessfulTxs, ccReceipts); err != nil {
return nil, fmt.Errorf("batch computation failed due to cross chain messages. Cause: %w", err)
}
for _, tx := range ccSuccessfulTxs {
fmt.Printf("Successful TX for batch with hash: %s\n", tx.Hash().Hex())
}

if failForEmptyBatch &&
len(txReceipts) == 0 &&
Expand Down Expand Up @@ -245,6 +253,15 @@ func (executor *batchExecutor) ComputeBatch(ctx context.Context, context *BatchE
l.BlockHash = copyBatch.Hash()
}
}
for _, tx := range freeTransactions.ToTransactions() {
fmt.Printf("Free tx hash: %s\n", tx.Hash().Hex())
}
for _, tx := range transactionsToProcess.ToTransactions() {
fmt.Printf("TransactionsToProcess tx hash: %s\n", tx.Hash().Hex())
}
for _, tx := range copyBatch.Transactions {
fmt.Printf("Computed batch TX hash: %s\n", tx.Hash().Hex())
}
maps.Copy(createdContracts, createdContractsSyn)
return &ComputedBatch{
Batch: &copyBatch,
Expand Down
8 changes: 8 additions & 0 deletions go/enclave/nodetype/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func (s *sequencer) createNewHeadBatch(ctx context.Context, l1HeadBlock *common.
for _, group := range pendingTransactions {
// lazily resolve transactions until the batch runs out of space
for _, lazyTx := range group {
fmt.Printf("Mempool tx hash: %s\n", lazyTx.Hash.Hex())
if tx := lazyTx.Resolve(); tx != nil {
err = limiter.AcceptTransaction(tx)
if err != nil {
Expand All @@ -255,6 +256,9 @@ func (s *sequencer) createNewHeadBatch(ctx context.Context, l1HeadBlock *common.
return err
}

for _, tx := range transactions {
fmt.Printf("sequencer producing new head batch tx: %s\n", tx.Hash().Hex())
}
// todo - time is set only here; take from l1 block?
if _, err := s.produceBatch(ctx, sequencerNo.Add(sequencerNo, big.NewInt(1)), l1HeadBlock.Hash(), headBatch.Hash(), transactions, uint64(time.Now().Unix()), skipBatchIfEmpty); err != nil {
if errors.Is(err, components.ErrNoTransactionsToProcess) {
Expand Down Expand Up @@ -435,6 +439,9 @@ func (s *sequencer) duplicateBatches(ctx context.Context, l1Head *types.Block, n
return fmt.Errorf("could not fetch transactions to duplicate. Cause %w", err)
}
// create the duplicate and store/broadcast it, recreate batch even if it was empty
for _, tx := range transactions {
fmt.Printf("sequencer dublicate batch tx: %s\n", tx.Hash().Hex())
}
cb, err := s.produceBatch(ctx, sequencerNo, l1Head.Hash(), currentHead, transactions, orphanBatch.Time, false)
if err != nil {
return fmt.Errorf("could not produce batch. Cause %w", err)
Expand All @@ -457,6 +464,7 @@ func (s *sequencer) duplicateBatches(ctx context.Context, l1Head *types.Block, n
}

func (s *sequencer) SubmitTransaction(transaction *common.L2Tx) error {
fmt.Printf("Adding tx to mempool: %s\n", transaction.Hash().Hex())
return s.mempool.Add(transaction)
}

Expand Down
1 change: 1 addition & 0 deletions go/enclave/rpc/SubmitTx.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func SubmitTxExecute(builder *CallBuilder[common.L2Tx, gethcommon.Hash], rpc *En
return nil
}
h := builder.Param.Hash()
fmt.Printf("Submit TX execute hash: %s\n", h.Hex())
builder.ReturnValue = &h
return nil
}
7 changes: 6 additions & 1 deletion go/enclave/rpc/vk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"context"
"encoding/json"
"errors"
"fmt"

Check failure on line 7 in go/enclave/rpc/vk_utils.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)

"github.com/ten-protocol/go-ten/go/common/rpc"
"github.com/ten-protocol/go-ten/go/common/viewingkey"

gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ten-protocol/go-ten/go/common"
Expand Down Expand Up @@ -54,6 +54,7 @@
) (*responses.EnclaveResponse, common.SystemError) {
// 1. Decrypt request
plaintextRequest, err := encManager.DecryptBytes(encReq)
fmt.Printf("Plaintext request: %s\n", plaintextRequest)
if err != nil {
return responses.AsPlaintextError(fmt.Errorf("could not decrypt params - %w", err)), nil
}
Expand All @@ -63,6 +64,10 @@
if err := json.Unmarshal(plaintextRequest, &decodedRequest); err != nil {
return responses.AsPlaintextError(fmt.Errorf("could not unmarshal params - %w", err)), nil
}
userId := viewingkey.CalculateUserID(decodedRequest.VK.PublicKey)

recoveredSignerAddress, _ := viewingkey.CheckSignature(userId, decodedRequest.VK.SignatureWithAccountKey, 1337, decodedRequest.VK.SignatureType)
fmt.Printf("Recovered signer address: %s\n", recoveredSignerAddress.Hex())

// 3. Verify the VK
if decodedRequest.VK == nil {
Expand Down
3 changes: 3 additions & 0 deletions go/enclave/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ func (s *storageImpl) StoreBatch(ctx context.Context, batch *core.Batch, convert
return err
}

for _, tx := range batch.Transactions {
fmt.Printf("Enclave storing tx: %s\n", tx.Hash().Hex())
}
if err := enclavedb.WriteTransactions(ctx, dbTx, batch, senders); err != nil {
return fmt.Errorf("could not write transactions. Cause: %w", err)
}
Expand Down
8 changes: 7 additions & 1 deletion go/host/storage/hostdb/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ func AddBatch(dbtx *dbTransaction, statements *SQLStatements, batch *common.ExtB
}
return fmt.Errorf("host failed to insert batch: %w", err)
}

var totalCount int
_ = dbtx.tx.QueryRow(countTxs).Scan(&totalCount)
if len(batch.TxHashes) > 0 {
insert := statements.InsertTransactions
args := make([]any, 0)
fmt.Printf("Total before inserting tx: %d\n", int64(totalCount))
fmt.Printf("Inserting %d new tx hashes \n", len(batch.TxHashes))
for i, txHash := range batch.TxHashes {
insert += fmt.Sprintf(" (%s, %s),", statements.GetPlaceHolder(i*2+1), statements.GetPlaceHolder(i*2+2))
args = append(args, txHash.Bytes(), batch.SeqNo().Uint64())
fmt.Printf("Inserting tx with hash: %s %d\n", txHash.Hex(), batch.SeqNo().Uint64())
}
insert = strings.TrimRight(insert, ",")
_, err = dbtx.tx.Exec(insert, args...)
Expand All @@ -57,6 +61,8 @@ func AddBatch(dbtx *dbTransaction, statements *SQLStatements, batch *common.ExtB
}
}

_ = dbtx.tx.QueryRow(countTxs).Scan(&totalCount)
fmt.Printf("Total after inserting tx: %d\n", int64(totalCount))
var currentTotal int
err = dbtx.tx.QueryRow(selectTxCount).Scan(&currentTotal)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go/obsclient/authclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (ac *AuthObsClient) CallContract(ctx context.Context, msg ethereum.CallMsg,
}

func (ac *AuthObsClient) SendTransaction(ctx context.Context, signedTx *types.Transaction) error {
fmt.Printf("Send Transaction: %s\n", signedTx.Hash().Hex())
var result responses.RawTxType
err := ac.rpcClient.CallContext(ctx, &result, rpc.SendRawTransaction, encodeTx(signedTx))
if err != nil {
Expand Down
Loading