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

ledger: rename "internal" to "eval" #5236

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ledger/acctupdates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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/ledger/internal"
"github.com/algorand/go-algorand/ledger/eval"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/ledger/store/trackerdb"
"github.com/algorand/go-algorand/ledger/store/trackerdb/sqlitedriver"
Expand Down Expand Up @@ -191,7 +191,7 @@ func (ml *mockLedgerForTracker) addMockBlock(be blockEntry, delta ledgercore.Sta
return nil
}

func (ml *mockLedgerForTracker) trackerEvalVerified(blk bookkeeping.Block, accUpdatesLedger internal.LedgerForEvaluator) (ledgercore.StateDelta, error) {
func (ml *mockLedgerForTracker) trackerEvalVerified(blk bookkeeping.Block, accUpdatesLedger eval.LedgerForEvaluator) (ledgercore.StateDelta, error) {
// support returning the deltas if the client explicitly provided them by calling addMockBlock, otherwise,
// just return an empty state delta ( since the client clearly didn't care about these )
if len(ml.deltas) > int(blk.Round()) {
Expand Down
4 changes: 2 additions & 2 deletions ledger/archival_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/transactions/logic"
"github.com/algorand/go-algorand/ledger/internal"
"github.com/algorand/go-algorand/ledger/eval"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/ledger/store/blockdb"
"github.com/algorand/go-algorand/ledger/store/trackerdb"
Expand Down Expand Up @@ -68,7 +68,7 @@ func (wl *wrappedLedger) BlockHdr(rnd basics.Round) (bookkeeping.BlockHeader, er
return wl.l.BlockHdr(rnd)
}

func (wl *wrappedLedger) trackerEvalVerified(blk bookkeeping.Block, accUpdatesLedger internal.LedgerForEvaluator) (ledgercore.StateDelta, error) {
func (wl *wrappedLedger) trackerEvalVerified(blk bookkeeping.Block, accUpdatesLedger eval.LedgerForEvaluator) (ledgercore.StateDelta, error) {
return wl.l.trackerEvalVerified(blk, accUpdatesLedger)
}

Expand Down
10 changes: 5 additions & 5 deletions ledger/double_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/txntest"
"github.com/algorand/go-algorand/ledger/internal"
"github.com/algorand/go-algorand/ledger/eval"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/protocol"
"github.com/stretchr/testify/require"
Expand All @@ -47,7 +47,7 @@ type DoubleLedger struct {
generator *Ledger
validator *Ledger

eval *internal.BlockEvaluator
eval *eval.BlockEvaluator
}

func (dl DoubleLedger) Close() {
Expand All @@ -62,7 +62,7 @@ func NewDoubleLedger(t *testing.T, balances bookkeeping.GenesisBalances, cv prot
return DoubleLedger{t, g, v, nil}
}

func (dl *DoubleLedger) beginBlock() *internal.BlockEvaluator {
func (dl *DoubleLedger) beginBlock() *eval.BlockEvaluator {
dl.eval = nextBlock(dl.t, dl.generator)
return dl.eval
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func checkBlock(t *testing.T, checkLedger *Ledger, vb *ledgercore.ValidatedBlock
// require.Equal(t, vb.Delta().Accts, cb.Delta().Accts)
}

func nextCheckBlock(t testing.TB, ledger *Ledger, rs bookkeeping.RewardsState) *internal.BlockEvaluator {
func nextCheckBlock(t testing.TB, ledger *Ledger, rs bookkeeping.RewardsState) *eval.BlockEvaluator {
rnd := ledger.Latest()
hdr, err := ledger.BlockHdr(rnd)
require.NoError(t, err)
Expand All @@ -211,7 +211,7 @@ func nextCheckBlock(t testing.TB, ledger *Ledger, rs bookkeeping.RewardsState) *
nextHdr.RewardsState = rs
// follow nextBlock, which does this for determinism
nextHdr.TimeStamp = hdr.TimeStamp + 1
eval, err := internal.StartEvaluator(ledger, nextHdr, internal.EvaluatorOptions{
eval, err := eval.StartEvaluator(ledger, nextHdr, eval.EvaluatorOptions{
Generate: false,
Validate: true, // Do the complete checks that a new txn would be subject to
})
Expand Down
5 changes: 3 additions & 2 deletions ledger/internal/appcow.go → ledger/eval/appcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"fmt"
Expand All @@ -29,7 +29,7 @@ import (
"github.com/algorand/go-algorand/protocol"
)

//msgp: ignore storageAction
//msgp:ignore storageAction
type storageAction uint64

const (
Expand Down Expand Up @@ -74,6 +74,7 @@ func (vd valueDelta) serialize() (vdelta basics.ValueDelta, ok bool) {
}

// stateDelta is similar to basics.StateDelta but stores both values before and after change
//
//msgp:ignore stateDelta
type stateDelta map[string]valueDelta

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion ledger/internal/assetcow.go → ledger/eval/assetcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"github.com/algorand/go-algorand/data/basics"
Expand Down
2 changes: 1 addition & 1 deletion ledger/internal/cow.go → ledger/eval/cow.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion ledger/internal/cow_test.go → ledger/eval/cow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"reflect"
Expand Down
4 changes: 2 additions & 2 deletions ledger/internal/eval.go → ledger/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"context"
Expand All @@ -30,7 +30,7 @@ import (
"github.com/algorand/go-algorand/data/transactions/logic"
"github.com/algorand/go-algorand/data/transactions/verify"
"github.com/algorand/go-algorand/ledger/apply"
"github.com/algorand/go-algorand/ledger/internal/prefetcher"
"github.com/algorand/go-algorand/ledger/eval/prefetcher"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
Expand Down
2 changes: 1 addition & 1 deletion ledger/internal/eval_test.go → ledger/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with go-algorand. If not, see <https://www.gnu.org/licenses/>.

package internal
package eval

import (
"fmt"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/ledger/internal"
"github.com/algorand/go-algorand/ledger/internal/prefetcher"
"github.com/algorand/go-algorand/ledger/eval"
"github.com/algorand/go-algorand/ledger/eval/prefetcher"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/test/partitiontest"
Expand Down Expand Up @@ -290,7 +290,7 @@ func runEval(t *testing.T, l *prefetcherAlignmentTestLedger, txn transactions.Tr
require.NoError(t, err)
block := bookkeeping.MakeBlock(genesisBlockHeader)

eval, err := internal.StartEvaluator(l, block.BlockHeader, internal.EvaluatorOptions{})
eval, err := eval.StartEvaluator(l, block.BlockHeader, eval.EvaluatorOptions{})
require.NoError(t, err)

err = eval.TransactionGroup(makeGroupFromTxn(txn))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/ledger/internal/prefetcher"
"github.com/algorand/go-algorand/ledger/eval/prefetcher"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/test/partitiontest"
Expand Down
4 changes: 2 additions & 2 deletions ledger/evalbench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/transactions/logic"
"github.com/algorand/go-algorand/ledger/internal"
"github.com/algorand/go-algorand/ledger/eval"
"github.com/algorand/go-algorand/ledger/ledgercore"
ledgertesting "github.com/algorand/go-algorand/ledger/testing"
"github.com/algorand/go-algorand/logging"
Expand Down Expand Up @@ -491,7 +491,7 @@ func benchmarkBlockEvaluator(b *testing.B, inMem bool, withCrypto bool, proto pr
if withCrypto {
_, err = l2.Validate(context.Background(), validatedBlock.Block(), backlogPool)
} else {
_, err = internal.Eval(context.Background(), l2, validatedBlock.Block(), false, nil, nil)
_, err = eval.Eval(context.Background(), l2, validatedBlock.Block(), false, nil, nil)
}
require.NoError(b, err)
}
Expand Down
6 changes: 3 additions & 3 deletions ledger/evalindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/ledger/internal"
"github.com/algorand/go-algorand/ledger/eval"
"github.com/algorand/go-algorand/ledger/ledgercore"
)

Expand Down Expand Up @@ -233,9 +233,9 @@ func makeIndexerLedgerConnector(il indexerLedgerForEval, genesisHash crypto.Dige
func EvalForIndexer(il indexerLedgerForEval, block *bookkeeping.Block, proto config.ConsensusParams, resources EvalForIndexerResources) (ledgercore.StateDelta, []transactions.SignedTxnInBlock, error) {
ilc := makeIndexerLedgerConnector(il, block.GenesisHash(), proto, block.Round()-1, resources)

eval, err := internal.StartEvaluator(
eval, err := eval.StartEvaluator(
ilc, block.BlockHeader,
internal.EvaluatorOptions{
eval.EvaluatorOptions{
PaysetHint: len(block.Payset),
ProtoParams: &proto,
Generate: false,
Expand Down
12 changes: 6 additions & 6 deletions ledger/fullblock_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/transactions/logic"
"github.com/algorand/go-algorand/data/transactions/verify"
"github.com/algorand/go-algorand/ledger/internal"
"github.com/algorand/go-algorand/ledger/eval"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/protocol"
Expand All @@ -53,7 +53,7 @@ type benchConfig struct {
acctToApp map[basics.Address]map[basics.AppIndex]struct{}
l0 *Ledger
l1 *Ledger
eval *internal.BlockEvaluator
eval *eval.BlockEvaluator
numPay uint64
numAst uint64
numApp uint64
Expand Down Expand Up @@ -119,7 +119,7 @@ func setupEnv(b *testing.B, numAccts int) (bc *benchConfig) {
require.NoError(b, err)

newBlk := bookkeeping.MakeBlock(blk.BlockHeader)
eval, err := l0.StartEvaluator(newBlk.BlockHeader, 5000, 0)
blockEvaluator, err := l0.StartEvaluator(newBlk.BlockHeader, 5000, 0)
require.NoError(b, err)

bc = &benchConfig{
Expand All @@ -132,7 +132,7 @@ func setupEnv(b *testing.B, numAccts int) (bc *benchConfig) {
acctToApp: acctToApp,
l0: l0,
l1: l1,
eval: eval,
eval: blockEvaluator,
}

// start the ledger with a pool of accounts
Expand All @@ -144,7 +144,7 @@ func setupEnv(b *testing.B, numAccts int) (bc *benchConfig) {
addBlock(bc)
vc := verify.GetMockedCache(true)
for _, blk := range bc.blocks {
_, err := internal.Eval(context.Background(), bc.l1, blk, true, vc, nil)
_, err := eval.Eval(context.Background(), bc.l1, blk, true, vc, nil)
require.NoError(b, err)
err = bc.l1.AddBlock(blk, cert)
require.NoError(b, err)
Expand Down Expand Up @@ -424,7 +424,7 @@ func benchmarkBlockValidationMix(b *testing.B, newAcctProb, payProb, astProb flo
tt := time.Now()
b.ResetTimer()
for _, blk := range bc.blocks {
_, err := internal.Eval(context.Background(), bc.l1, blk, true, vc, nil)
_, err := eval.Eval(context.Background(), bc.l1, blk, true, vc, nil)
require.NoError(b, err)
err = bc.l1.AddBlock(blk, cert)
require.NoError(b, err)
Expand Down
20 changes: 10 additions & 10 deletions ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/transactions/verify"
"github.com/algorand/go-algorand/ledger/apply"
"github.com/algorand/go-algorand/ledger/internal"
"github.com/algorand/go-algorand/ledger/eval"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/ledger/store/blockdb"
"github.com/algorand/go-algorand/ledger/store/trackerdb"
Expand Down Expand Up @@ -655,7 +655,7 @@ func (l *Ledger) BlockCert(rnd basics.Round) (blk bookkeeping.Block, cert agreem
func (l *Ledger) AddBlock(blk bookkeeping.Block, cert agreement.Certificate) error {
// passing nil as the executionPool is ok since we've asking the evaluator to skip verification.

updates, err := internal.Eval(context.Background(), l, blk, false, l.verifiedTxnCache, nil)
updates, err := eval.Eval(context.Background(), l, blk, false, l.verifiedTxnCache, nil)
if err != nil {
if errNSBE, ok := err.(ledgercore.ErrNonSequentialBlockEval); ok && errNSBE.EvaluatorRound <= errNSBE.LatestRound {
return ledgercore.BlockInLedgerError{
Expand Down Expand Up @@ -782,9 +782,9 @@ func (l *Ledger) trackerLog() logging.Logger {
// trackerEvalVerified is used by the accountUpdates to reconstruct the ledgercore.StateDelta from a given block during it's loadFromDisk execution.
// when this function is called, the trackers mutex is expected already to be taken. The provided accUpdatesLedger would allow the
// evaluator to shortcut the "main" ledger ( i.e. this struct ) and avoid taking the trackers lock a second time.
func (l *Ledger) trackerEvalVerified(blk bookkeeping.Block, accUpdatesLedger internal.LedgerForEvaluator) (ledgercore.StateDelta, error) {
func (l *Ledger) trackerEvalVerified(blk bookkeeping.Block, accUpdatesLedger eval.LedgerForEvaluator) (ledgercore.StateDelta, error) {
// passing nil as the executionPool is ok since we've asking the evaluator to skip verification.
return internal.Eval(context.Background(), accUpdatesLedger, blk, false, l.verifiedTxnCache, nil)
return eval.Eval(context.Background(), accUpdatesLedger, blk, false, l.verifiedTxnCache, nil)
}

// IsWritingCatchpointDataFile returns true when a catchpoint file is being generated.
Expand All @@ -808,9 +808,9 @@ func (l *Ledger) VerifiedTransactionCache() verify.VerifiedTransactionCache {
// provides a cap on the size of a single generated block size, when a non-zero value is passed.
// If a value of zero or less is passed to maxTxnBytesPerBlock, the consensus MaxTxnBytesPerBlock would
// be used instead.
func (l *Ledger) StartEvaluator(hdr bookkeeping.BlockHeader, paysetHint, maxTxnBytesPerBlock int) (*internal.BlockEvaluator, error) {
return internal.StartEvaluator(l, hdr,
internal.EvaluatorOptions{
func (l *Ledger) StartEvaluator(hdr bookkeeping.BlockHeader, paysetHint, maxTxnBytesPerBlock int) (*eval.BlockEvaluator, error) {
return eval.StartEvaluator(l, hdr,
eval.EvaluatorOptions{
PaysetHint: paysetHint,
Generate: true,
Validate: true,
Expand All @@ -828,7 +828,7 @@ func (l *Ledger) FlushCaches() {
// not a valid block (e.g., it has duplicate transactions, overspends some
// account, etc).
func (l *Ledger) Validate(ctx context.Context, blk bookkeeping.Block, executionPool execpool.BacklogPool) (*ledgercore.ValidatedBlock, error) {
delta, err := internal.Eval(ctx, l, blk, true, l.verifiedTxnCache, executionPool)
delta, err := eval.Eval(ctx, l, blk, true, l.verifiedTxnCache, executionPool)
if err != nil {
return nil, err
}
Expand All @@ -838,11 +838,11 @@ func (l *Ledger) Validate(ctx context.Context, blk bookkeeping.Block, executionP
}

// DebuggerLedger defines the minimal set of method required for creating a debug balances.
type DebuggerLedger = internal.LedgerForCowBase
type DebuggerLedger = eval.LedgerForCowBase

// MakeDebugBalances creates a ledger suitable for dryrun and debugger
func MakeDebugBalances(l DebuggerLedger, round basics.Round, proto protocol.ConsensusVersion, prevTimestamp int64) apply.Balances {
return internal.MakeDebugBalances(l, round, proto, prevTimestamp)
return eval.MakeDebugBalances(l, round, proto, prevTimestamp)
}

var ledgerInitblocksdbCount = metrics.NewCounter("ledger_initblocksdb_count", "calls")
Expand Down
Loading