Skip to content

Commit

Permalink
Reduced 'internalSnapshot' interface, removed unnecessary code.
Browse files Browse the repository at this point in the history
  • Loading branch information
nickeskov committed Oct 30, 2023
1 parent 51e23bf commit c1cfa38
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 121 deletions.
60 changes: 0 additions & 60 deletions pkg/proto/snapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type AtomicSnapshot interface {
/* is temporarily used to mark snapshots generated by tx diff that shouldn't be applied,
because balances diffs are applied later in the block. */
IsGeneratedByTxDiff() bool
IsInternal() bool
}

type WavesBalanceSnapshot struct {
Expand All @@ -31,20 +30,12 @@ type AssetBalanceSnapshot struct {
Balance uint64
}

func (s WavesBalanceSnapshot) IsInternal() bool {
return false
}

func (s AssetBalanceSnapshot) IsGeneratedByTxDiff() bool {
return true
}

func (s AssetBalanceSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAssetBalance(s) }

func (s AssetBalanceSnapshot) IsInternal() bool {
return false
}

type DataEntriesSnapshot struct { // AccountData in pb
Address WavesAddress
DataEntries []DataEntry
Expand All @@ -56,10 +47,6 @@ func (s DataEntriesSnapshot) IsGeneratedByTxDiff() bool {

func (s DataEntriesSnapshot) Apply(a SnapshotApplier) error { return a.ApplyDataEntries(s) }

func (s DataEntriesSnapshot) IsInternal() bool {
return false
}

type AccountScriptSnapshot struct {
SenderPublicKey crypto.PublicKey
Script Script
Expand All @@ -72,10 +59,6 @@ func (s AccountScriptSnapshot) IsGeneratedByTxDiff() bool {

func (s AccountScriptSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAccountScript(s) }

func (s AccountScriptSnapshot) IsInternal() bool {
return false
}

type AssetScriptSnapshot struct {
AssetID crypto.Digest
Script Script
Expand All @@ -87,10 +70,6 @@ func (s AssetScriptSnapshot) IsGeneratedByTxDiff() bool {

func (s AssetScriptSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAssetScript(s) }

func (s AssetScriptSnapshot) IsInternal() bool {
return false
}

type LeaseBalanceSnapshot struct {
Address WavesAddress
LeaseIn uint64
Expand All @@ -103,10 +82,6 @@ func (s LeaseBalanceSnapshot) IsGeneratedByTxDiff() bool {

func (s LeaseBalanceSnapshot) Apply(a SnapshotApplier) error { return a.ApplyLeaseBalance(s) }

func (s LeaseBalanceSnapshot) IsInternal() bool {
return false
}

type LeaseStateStatus struct {
Value LeaseStatus // can be only LeaseActive or LeaseCanceled
CancelHeight Height
Expand All @@ -129,10 +104,6 @@ func (s LeaseStateSnapshot) IsGeneratedByTxDiff() bool {

func (s LeaseStateSnapshot) Apply(a SnapshotApplier) error { return a.ApplyLeaseState(s) }

func (s LeaseStateSnapshot) IsInternal() bool {
return false
}

type SponsorshipSnapshot struct {
AssetID crypto.Digest
MinSponsoredFee uint64
Expand All @@ -144,10 +115,6 @@ func (s SponsorshipSnapshot) IsGeneratedByTxDiff() bool {

func (s SponsorshipSnapshot) Apply(a SnapshotApplier) error { return a.ApplySponsorship(s) }

func (s SponsorshipSnapshot) IsInternal() bool {
return false
}

type AliasSnapshot struct {
Address WavesAddress
Alias Alias
Expand All @@ -159,10 +126,6 @@ func (s AliasSnapshot) IsGeneratedByTxDiff() bool {

func (s AliasSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAlias(s) }

func (s AliasSnapshot) IsInternal() bool {
return false
}

// FilledVolumeFeeSnapshot Filled Volume and Fee.
type FilledVolumeFeeSnapshot struct { // OrderFill
OrderID crypto.Digest
Expand All @@ -176,10 +139,6 @@ func (s FilledVolumeFeeSnapshot) IsGeneratedByTxDiff() bool {

func (s FilledVolumeFeeSnapshot) Apply(a SnapshotApplier) error { return a.ApplyFilledVolumeAndFee(s) }

func (s FilledVolumeFeeSnapshot) IsInternal() bool {
return false
}

type StaticAssetInfoSnapshot struct {
AssetID crypto.Digest
SourceTransactionID crypto.Digest
Expand Down Expand Up @@ -210,10 +169,6 @@ func (s AssetVolumeSnapshot) IsGeneratedByTxDiff() bool {

func (s AssetVolumeSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAssetVolume(s) }

func (s AssetVolumeSnapshot) IsInternal() bool {
return false
}

type AssetDescriptionSnapshot struct { // AssetNameAndDescription in pb
AssetID crypto.Digest
AssetName string
Expand All @@ -227,10 +182,6 @@ func (s AssetDescriptionSnapshot) IsGeneratedByTxDiff() bool {

func (s AssetDescriptionSnapshot) Apply(a SnapshotApplier) error { return a.ApplyAssetDescription(s) }

func (s AssetDescriptionSnapshot) IsInternal() bool {
return false
}

type TransactionStatusSnapshot struct {
TransactionID crypto.Digest
Status TransactionStatus
Expand All @@ -244,14 +195,6 @@ func (s TransactionStatusSnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s TransactionStatusSnapshot) IsInternal() bool {
return false
}

type InternalSnapshot interface {
InternalSnapshotMarker()
}

type SnapshotApplier interface {
ApplyWavesBalance(snapshot WavesBalanceSnapshot) error
ApplyLeaseBalance(snapshot LeaseBalanceSnapshot) error
Expand All @@ -267,7 +210,4 @@ type SnapshotApplier interface {
ApplyDataEntries(snapshot DataEntriesSnapshot) error
ApplyLeaseState(snapshot LeaseStateSnapshot) error
ApplyTransactionsStatus(snapshot TransactionStatusSnapshot) error

/* Internal snapshots. Applied only in the full node mode */
ApplyInternalSnapshot(internalSnapshot InternalSnapshot) error
}
43 changes: 0 additions & 43 deletions pkg/state/internal_snapshots_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

type internalSnapshot interface {
IsGeneratedByTxDiff() bool
ApplyInternal(internalSnapshotApplier) error
}

Expand All @@ -27,68 +26,26 @@ type InternalDAppComplexitySnapshot struct {
ScriptIsEmpty bool
}

func (s InternalDAppComplexitySnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s InternalDAppComplexitySnapshot) Apply(a proto.SnapshotApplier) error {
return a.ApplyInternalSnapshot(&s)
}

func (s InternalDAppComplexitySnapshot) ApplyInternal(a internalSnapshotApplier) error {
return a.ApplyDAppComplexity(s)
}

func (s InternalDAppComplexitySnapshot) IsInternal() bool {
return true
}

func (s *InternalDAppComplexitySnapshot) InternalSnapshotMarker() {}

type InternalDAppUpdateComplexitySnapshot struct {
ScriptAddress proto.WavesAddress
Estimation ride.TreeEstimation
ScriptIsEmpty bool
}

func (s InternalDAppUpdateComplexitySnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s InternalDAppUpdateComplexitySnapshot) Apply(a proto.SnapshotApplier) error {
return a.ApplyInternalSnapshot(&s)
}

func (s InternalDAppUpdateComplexitySnapshot) ApplyInternal(a internalSnapshotApplier) error {
return a.ApplyDAppUpdateComplexity(s)
}

func (s InternalDAppUpdateComplexitySnapshot) IsInternal() bool {
return true
}

func (s *InternalDAppUpdateComplexitySnapshot) InternalSnapshotMarker() {}

type InternalAssetScriptComplexitySnapshot struct {
AssetID crypto.Digest
Estimation ride.TreeEstimation
ScriptIsEmpty bool
}

func (s InternalAssetScriptComplexitySnapshot) IsGeneratedByTxDiff() bool {
return false
}

func (s InternalAssetScriptComplexitySnapshot) Apply(a proto.SnapshotApplier) error {
return a.ApplyInternalSnapshot(&s)
}

func (s InternalAssetScriptComplexitySnapshot) ApplyInternal(a internalSnapshotApplier) error {
return a.ApplyAssetScriptComplexity(s)
}

func (s InternalAssetScriptComplexitySnapshot) IsInternal() bool {
return true
}

func (s *InternalAssetScriptComplexitySnapshot) InternalSnapshotMarker() {}
13 changes: 0 additions & 13 deletions pkg/state/snapshot_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,6 @@ func (a *blockSnapshotsApplier) ApplyTransactionsStatus(_ proto.TransactionStatu
return nil // no-op
}

func (a *blockSnapshotsApplier) ApplyInternalSnapshot(internalSnapshot proto.InternalSnapshot) error {
switch snapshot := internalSnapshot.(type) {
case *InternalDAppComplexitySnapshot:
return a.ApplyDAppComplexity(*snapshot)
case *InternalDAppUpdateComplexitySnapshot:
return a.ApplyDAppUpdateComplexity(*snapshot)
case *InternalAssetScriptComplexitySnapshot:
return a.ApplyAssetScriptComplexity(*snapshot)
default:
return errors.Errorf("failed to apply internal snapshot, unknown type (%T)", snapshot)
}
}

func (a *blockSnapshotsApplier) ApplyDAppComplexity(snapshot InternalDAppComplexitySnapshot) error {
scriptEstimation := scriptEstimation{currentEstimatorVersion: a.info.EstimatorVersion(),
scriptIsEmpty: snapshot.ScriptIsEmpty, estimation: snapshot.Estimation}
Expand Down
8 changes: 3 additions & 5 deletions pkg/state/tx_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ func (ts txSnapshot) Apply(a extendedSnapshotApplier) error {
}
}
for _, is := range ts.internal {
if !is.IsGeneratedByTxDiff() {
err := is.ApplyInternal(a)
if err != nil {
return errors.Wrap(err, "failed to apply internal transaction snapshot")
}
err := is.ApplyInternal(a)
if err != nil {
return errors.Wrap(err, "failed to apply internal transaction snapshot")
}
}
return nil
Expand Down

0 comments on commit c1cfa38

Please sign in to comment.