Skip to content

Commit

Permalink
ledger/eval refactor (algorand#700)
Browse files Browse the repository at this point in the history
refactor ledger/eval block validation
don't do crypto+lsig validation in eval
fix sync in backlog executer queue
clean up lots of logging to make tests quieter
  • Loading branch information
algobolson authored Jan 22, 2020
1 parent 4f4a372 commit c78ada0
Show file tree
Hide file tree
Showing 14 changed files with 217 additions and 108 deletions.
6 changes: 1 addition & 5 deletions data/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/logging/telemetryspec"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/util/execpool"
)

func incaddr(user *basics.Address) {
Expand Down Expand Up @@ -70,9 +69,6 @@ func BenchmarkAssemblePayset(b *testing.B) {
secrets := make([]*crypto.SignatureSecrets, numUsers)
addresses := make([]basics.Address, numUsers)

backlogPool := execpool.MakeBacklog(nil, 0, execpool.LowPriority, nil)
defer backlogPool.Shutdown()

genesis := make(map[basics.Address]basics.AccountData)
for i := 0; i < numUsers; i++ {
secret := keypair()
Expand Down Expand Up @@ -164,7 +160,7 @@ func BenchmarkAssemblePayset(b *testing.B) {
}
b.StartTimer()
newEmptyBlk := bookkeeping.MakeBlock(prev)
eval, err := l.StartEvaluator(newEmptyBlk.BlockHeader, tp, backlogPool)
eval, err := l.StartEvaluator(newEmptyBlk.BlockHeader)
if err != nil {
b.Errorf("could not make proposals at round %d: could not start evaluator: %v", next, err)
return
Expand Down
12 changes: 1 addition & 11 deletions data/pools/transactionPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,6 @@ func (pool *TransactionPool) OnNewBlock(block bookkeeping.Block, delta ledger.St
}
}

// alwaysVerifiedPool implements ledger.VerifiedTxnCache and returns every
// transaction as verified.
type alwaysVerifiedPool struct {
pool *TransactionPool
}

func (*alwaysVerifiedPool) Verified(txn transactions.SignedTxn, params verify.Params) bool {
return true
}

func (pool *TransactionPool) addToPendingBlockEvaluatorOnce(txgroup []transactions.SignedTxn) error {
r := pool.pendingBlockEvaluator.Round() + pool.numPendingWholeBlocks
for _, tx := range txgroup {
Expand Down Expand Up @@ -529,7 +519,7 @@ func (pool *TransactionPool) recomputeBlockEvaluator(committedTxIds map[transact

next := bookkeeping.MakeBlock(prev)
pool.numPendingWholeBlocks = 0
pool.pendingBlockEvaluator, err = pool.ledger.StartEvaluator(next.BlockHeader, &alwaysVerifiedPool{pool}, nil)
pool.pendingBlockEvaluator, err = pool.ledger.StartEvaluator(next.BlockHeader)
if err != nil {
logging.Base().Warnf("TransactionPool.recomputeBlockEvaluator: cannot start evaluator: %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion data/pools/transactionPool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func newBlockEvaluator(t TestingT, l *ledger.Ledger) *ledger.BlockEvaluator {
require.NoError(t, err)

next := bookkeeping.MakeBlock(prev)
eval, err := l.StartEvaluator(next.BlockHeader, &alwaysVerifiedPool{}, nil)
eval, err := l.StartEvaluator(next.BlockHeader)
require.NoError(t, err)

return eval
Expand Down
2 changes: 2 additions & 0 deletions ledger/accountdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func TestAccountDBInit(t *testing.T) {
proto := config.Consensus[protocol.ConsensusCurrentVersion]

dbs := dbOpenTest(t)
setDbLogging(t, dbs)
defer dbs.close()

tx, err := dbs.wdb.Handle.Begin()
Expand All @@ -180,6 +181,7 @@ func TestAccountDBRound(t *testing.T) {
proto := config.Consensus[protocol.ConsensusCurrentVersion]

dbs := dbOpenTest(t)
setDbLogging(t, dbs)
defer dbs.close()

tx, err := dbs.wdb.Handle.Begin()
Expand Down
8 changes: 6 additions & 2 deletions ledger/acctupdates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ import (
type mockLedgerForTracker struct {
dbs dbPair
blocks []blockEntry
log logging.Logger
}

func makeMockLedgerForTracker(t *testing.T) *mockLedgerForTracker {
dbs := dbOpenTest(t)
return &mockLedgerForTracker{dbs: dbs}
dblogger := logging.TestingLog(t)
dbs.rdb.SetLogger(dblogger)
dbs.wdb.SetLogger(dblogger)
return &mockLedgerForTracker{dbs: dbs, log: dblogger}
}

func (ml *mockLedgerForTracker) close() {
Expand Down Expand Up @@ -77,7 +81,7 @@ func (ml *mockLedgerForTracker) trackerDB() dbPair {
}

func (ml *mockLedgerForTracker) trackerLog() logging.Logger {
return logging.Base()
return ml.log
}

func checkAcctUpdates(t *testing.T, au *accountUpdates, base basics.Round, latestRnd basics.Round, accts []map[basics.Address]basics.AccountData, rewards []uint64, proto config.ConsensusParams) {
Expand Down
8 changes: 5 additions & 3 deletions ledger/archival_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ func TestArchival(t *testing.T) {
genesisInitState := getInitState()
const inMem = true
const archival = true
l, err := OpenLedger(logging.Base(), dbName, inMem, genesisInitState, archival)
log := logging.TestingLog(t)
l, err := OpenLedger(log, dbName, inMem, genesisInitState, archival)
require.NoError(t, err)
defer l.Close()
wl := &wrappedLedger{
Expand Down Expand Up @@ -495,7 +496,8 @@ func TestArchivalFromNonArchival(t *testing.T) {
const inMem = false // use persistent storage
archival := false

l, err := OpenLedger(logging.Base(), dbPrefix, inMem, genesisInitState, archival)
log := logging.TestingLog(t)
l, err := OpenLedger(log, dbPrefix, inMem, genesisInitState, archival)
require.NoError(t, err)
blk := genesisInitState.Block

Expand Down Expand Up @@ -524,7 +526,7 @@ func TestArchivalFromNonArchival(t *testing.T) {
l.Close()

archival = true
l, err = OpenLedger(logging.Base(), dbPrefix, inMem, genesisInitState, archival)
l, err = OpenLedger(log, dbPrefix, inMem, genesisInitState, archival)
require.NoError(t, err)
defer l.Close()

Expand Down
10 changes: 10 additions & 0 deletions ledger/blockdb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
)

Expand Down Expand Up @@ -100,8 +101,15 @@ func checkBlockDB(t *testing.T, tx *sql.Tx, blocks []blockEntry) {
require.Error(t, err)
}

func setDbLogging(t *testing.T, dbs dbPair) {
dblogger := logging.TestingLog(t)
dbs.rdb.SetLogger(dblogger)
dbs.wdb.SetLogger(dblogger)
}

func TestBlockDBEmpty(t *testing.T) {
dbs := dbOpenTest(t)
setDbLogging(t, dbs)
defer dbs.close()

tx, err := dbs.wdb.Handle.Begin()
Expand All @@ -115,6 +123,7 @@ func TestBlockDBEmpty(t *testing.T) {

func TestBlockDBInit(t *testing.T) {
dbs := dbOpenTest(t)
setDbLogging(t, dbs)
defer dbs.close()

tx, err := dbs.wdb.Handle.Begin()
Expand All @@ -134,6 +143,7 @@ func TestBlockDBInit(t *testing.T) {

func TestBlockDBAppend(t *testing.T) {
dbs := dbOpenTest(t)
setDbLogging(t, dbs)
defer dbs.close()

tx, err := dbs.wdb.Handle.Begin()
Expand Down
Loading

0 comments on commit c78ada0

Please sign in to comment.