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

Only encode state change metadata if flag is set #884

Merged
merged 1 commit into from
Dec 22, 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
3 changes: 2 additions & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ func SetupRunFlags(cmd *cobra.Command) {
cmd.PersistentFlags().Bool("log-db-summary-snapshots", false, "The node will log a snapshot of all DB keys every 30s.")
cmd.PersistentFlags().Bool("datadog-profiler", false, "Enable the DataDog profiler for performance testing")
cmd.PersistentFlags().Bool("time-events", false, "Enable simple event timer, helpful in hands-on performance testing")

cmd.PersistentFlags().String("state-change-dir", "", "The directory for state change logs. WARNING: Changing this "+
"from an empty string to a non-empty string (or from a non-empty string to the empty string) requires a resync.")
cmd.PersistentFlags().VisitAll(func(flag *pflag.Flag) {
viper.BindPFlag(flag.Name, flag)
})
Expand Down
28 changes: 26 additions & 2 deletions lib/block_view_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"github.com/spf13/viper"
"io"
"math"
"math/big"
Expand Down Expand Up @@ -883,6 +884,17 @@ type UtxoOperation struct {
StateChangeMetadata DeSoEncoder
}

// FIXME: This hackIsRunningStateSyncer() call is a hack to get around the fact that
// we don't have a way to not require a resync while introducing the state change
// metadata to the utxo operation struct. We don't want to use a block height to gate
// this because we want to be able to get state change metadata for ALL transactions.
// We should replace this with a more elegant solution, a better hack, or bundle it
// in with a release that requires a resync anyway. We should remove this function
// when we have a better solution in place.
func hackIsRunningStateSyncer() bool {
return viper.GetString("state-change-dir") != ""
}

func (op *UtxoOperation) RawEncodeWithoutMetadata(blockHeight uint64, skipMetadata ...bool) []byte {
var data []byte
// Type
Expand Down Expand Up @@ -1199,7 +1211,13 @@ func (op *UtxoOperation) RawEncodeWithoutMetadata(blockHeight uint64, skipMetada
}

// StateChangeMetadata
if op.StateChangeMetadata != nil {
// FIXME: This hackIsRunningStateSyncer() call is a hack to get around the fact that
// we don't have a way to not require a resync while introducing the state change
// metadata to the utxo operation struct. We don't want to use a block height to gate
// this because we want to be able to get state change metadata for ALL transactions.
// We should replace this with a more elegant solution, a better hack, or bundle it
// in with a release that requires a resync anyway.
if hackIsRunningStateSyncer() && op.StateChangeMetadata != nil {
data = append(data, EncodeToBytes(blockHeight, op.StateChangeMetadata, skipMetadata...)...)
}

Expand Down Expand Up @@ -1820,7 +1838,13 @@ func (op *UtxoOperation) RawDecodeWithoutMetadata(blockHeight uint64, rr *bytes.

// DeSoEncoder
stateChangeMetadata := GetStateChangeMetadataFromOpType(op.Type)
if stateChangeMetadata != nil {
// FIXME: This hackIsRunningStateSyncer() call is a hack to get around the fact that
// we don't have a way to not require a resync while introducing the state change
// metadata to the utxo operation struct. We don't want to use a block height to gate
// this because we want to be able to get state change metadata for ALL transactions.
// We should replace this with a more elegant solution, a better hack, or bundle it
// in with a release that requires a resync anyway.
if hackIsRunningStateSyncer() && stateChangeMetadata != nil {
if exist, err := DecodeFromBytes(stateChangeMetadata, rr); exist && err == nil {
op.StateChangeMetadata = stateChangeMetadata
} else if err != nil {
Expand Down
Loading