diff options
Diffstat (limited to 'ledger/ledger.go')
-rw-r--r-- | ledger/ledger.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/ledger/ledger.go b/ledger/ledger.go index 458ce3d53..fa1be1a76 100644 --- a/ledger/ledger.go +++ b/ledger/ledger.go @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2023 Algorand, Inc. +// Copyright (C) 2019-2024 Algorand, Inc. // This file is part of go-algorand // // go-algorand is free software: you can redistribute it and/or modify @@ -173,7 +173,7 @@ func OpenLedger[T string | DirsAndPrefix]( start := time.Now() ledgerInitblocksdbCount.Inc(nil) err = l.blockDBs.Wdb.Atomic(func(ctx context.Context, tx *sql.Tx) error { - return initBlocksDB(tx, l, []bookkeeping.Block{genesisInitState.Block}, cfg.Archival) + return initBlocksDB(tx, l.log, []bookkeeping.Block{genesisInitState.Block}, cfg.Archival) }) ledgerInitblocksdbMicros.AddMicrosecondsSince(start, nil) if err != nil { @@ -364,7 +364,7 @@ func (l *Ledger) setSynchronousMode(ctx context.Context, synchronousMode db.Sync // initBlocksDB performs DB initialization: // - creates and populates it with genesis blocks // - ensures DB is in good shape for archival mode and resets it if not -func initBlocksDB(tx *sql.Tx, l *Ledger, initBlocks []bookkeeping.Block, isArchival bool) (err error) { +func initBlocksDB(tx *sql.Tx, log logging.Logger, initBlocks []bookkeeping.Block, isArchival bool) (err error) { err = blockdb.BlockInit(tx, initBlocks) if err != nil { err = fmt.Errorf("initBlocksDB.blockInit %v", err) @@ -382,7 +382,7 @@ func initBlocksDB(tx *sql.Tx, l *Ledger, initBlocks []bookkeeping.Block, isArchi // Detect possible problem - archival node needs all block but have only subsequence of them // So reset the DB and init it again if earliest != basics.Round(0) { - l.log.Warnf("resetting blocks DB (earliest block is %v)", earliest) + log.Warnf("resetting blocks DB (earliest block is %v)", earliest) err := blockdb.BlockResetDB(tx) if err != nil { err = fmt.Errorf("initBlocksDB.blockResetDB %v", err) @@ -657,6 +657,15 @@ func (l *Ledger) CheckDup(currentProto config.ConsensusParams, current basics.Ro return l.txTail.checkDup(currentProto, current, firstValid, lastValid, txid, txl) } +// CheckConfirmedTail checks if a transaction txid happens to have LastValid greater than the current round at the time of calling and has been already committed to the ledger. +// If both conditions are met it returns true. +// This function could be used as filter to check if a transaction is committed to the ledger, and no extra checks needed if it says true. +// +// Note, this cannot be used to check if transaction happened or not in past MaxTxnLife rounds. +func (l *Ledger) CheckConfirmedTail(txid transactions.Txid) (basics.Round, bool) { + return l.txTail.checkConfirmed(txid) +} + // Latest returns the latest known block round added to the ledger. func (l *Ledger) Latest() basics.Round { return l.blockQ.latest() |