diff --git a/cmd/thalos/server.go b/cmd/thalos/server.go index 6f1ef98..7f01190 100644 --- a/cmd/thalos/server.go +++ b/cmd/thalos/server.go @@ -398,6 +398,8 @@ func serverCmd(cmd *cobra.Command, args []string) { processor.SetBlacklist(conf.Ship.Blacklist) processor.SetTableDeltaWhitelist(conf.Ship.TableDeltaWhitelist) + processor.SetPostTransactions(conf.Ship.EnableTransactions) + processor.SetPostActions(conf.Ship.EnableActions) processor.FetchDeltas(conf.Ship.EnableTableDeltas) // Run the application diff --git a/config.example.yml b/config.example.yml index 0c117e7..3d81ea3 100644 --- a/config.example.yml +++ b/config.example.yml @@ -46,6 +46,12 @@ ship: # If true, Thalos will process table deltas # table_deltas: false + # If false, thalos will skip posting transaction trace messages. + # transactions: true + + # If false, thalos will skip posting action trace messages. + # actions: true + # Optional: whitelist table deltas by contract and table. # When set, thalos will only process `contract_row` deltas where both # `code` and `table` match this whitelist. diff --git a/internal/config/builder.go b/internal/config/builder.go index 0bc8874..baa1364 100644 --- a/internal/config/builder.go +++ b/internal/config/builder.go @@ -59,6 +59,8 @@ func NewBuilder() *Builder { "ship.chain": "chain", "ship.blacklist": "blacklist", "ship.blacklist_is_whitelist": "blacklist-is-whitelist", + "ship.transactions": "transactions", + "ship.actions": "actions", "ship.table_deltas": "table-deltas", "ship.table_delta_whitelist": "table-delta-whitelist", }, diff --git a/internal/config/builder_test.go b/internal/config/builder_test.go index 670eac4..6fbe3b7 100644 --- a/internal/config/builder_test.go +++ b/internal/config/builder_test.go @@ -41,6 +41,8 @@ func TestBuilder(t *testing.T) { EndBlockNum: 23872222, IrreversibleOnly: true, MaxMessagesInFlight: 1337, + EnableTransactions: false, + EnableActions: false, Blacklist: *filter.New(map[string][]string{ "eosio": {"noop"}, "contract": {"skip1", "skip2"}, @@ -87,6 +89,8 @@ ship: url: "127.0.0.1:8089" irreversible_only: true max_messages_in_flight: 1337 + transactions: false + actions: false start_block_num: 23671836 end_block_num: 23872222 table_delta_whitelist: @@ -136,6 +140,8 @@ func TestBuilder_WithDefaultConfig(t *testing.T) { StartBlockNum: shipclient.NULL_BLOCK_NUMBER, EndBlockNum: shipclient.NULL_BLOCK_NUMBER, MaxMessagesInFlight: 10, + EnableTransactions: true, + EnableActions: true, EnableTableDeltas: true, Blacklist: *filter.New(nil).SetMode(filter.Exclude), TableDeltaWhitelist: *filter.New(nil).SetMode(filter.Exclude), @@ -186,6 +192,8 @@ func TestBuilder_Flags(t *testing.T) { require.NoError(t, flags.Set("chain", "wax")) require.NoError(t, flags.Set("blacklist", "contract:action1,contract:action2,contract2:action1")) require.NoError(t, flags.Set("blacklist-is-whitelist", "true")) + require.NoError(t, flags.Set("transactions", "false")) + require.NoError(t, flags.Set("actions", "false")) require.NoError(t, flags.Set("table-deltas", "false")) require.NoError(t, flags.Set("table-delta-whitelist", "eosio.token:accounts,mycontract:*")) @@ -214,6 +222,8 @@ func TestBuilder_Flags(t *testing.T) { EndBlockNum: 329408392, MaxMessagesInFlight: 98, IrreversibleOnly: true, + EnableTransactions: false, + EnableActions: false, Chain: "wax", Blacklist: *filter.New(map[string][]string{ "contract": {"action1", "action2"}, diff --git a/internal/config/cli.go b/internal/config/cli.go index 7055a1c..4cb55a1 100644 --- a/internal/config/cli.go +++ b/internal/config/cli.go @@ -48,6 +48,8 @@ func GetFlags() *pflag.FlagSet { flags.Bool("table-deltas", true, "True if thalos should receive and process table deltas from ship.") flags.StringSlice("table-delta-whitelist", []string{}, "Define a list of 'contract:table' pairs to whitelist table deltas. Use '*' for wildcard table names, e.g. 'mycontract:*'.") + flags.Bool("transactions", true, "True if thalos should post transaction trace messages.") + flags.Bool("actions", true, "True if thalos should post action trace messages.") flags.Bool("irreversible-only", false, "Only stream irreversible blocks from ship") flags.Int("max-msg-in-flight", 10, "Maximum messages that can be sent from SHIP without acknowledgement") diff --git a/internal/config/config.go b/internal/config/config.go index 4493a37..fc14511 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -39,6 +39,8 @@ type ShipConfig struct { Chain string `yaml:"chain" mapstructure:"chain"` Blacklist filter.List `yaml:"blacklist" mapstructure:"blacklist"` BlacklistIsWhitelist bool `yaml:"blacklist_is_whitelist" mapstructure:"blacklist_is_whitelist"` + EnableTransactions bool `yaml:"transactions" mapstructure:"transactions"` + EnableActions bool `yaml:"actions" mapstructure:"actions"` EnableTableDeltas bool `yaml:"table_deltas" mapstructure:"table_deltas"` TableDeltaWhitelist filter.List `yaml:"table_delta_whitelist" mapstructure:"table_delta_whitelist"` } diff --git a/internal/server/ship_processor.go b/internal/server/ship_processor.go index fb37163..4837fc0 100644 --- a/internal/server/ship_processor.go +++ b/internal/server/ship_processor.go @@ -45,16 +45,24 @@ type ShipProcessor struct { // Optional whitelist for contract_row table delta contract+table names. tableDeltaWhitelist filter.List + + // If false, TransactionTrace messages will not be posted. + postTransactions bool + + // If false, ActionTrace messages will not be posted. + postActions bool } // SpawnProcessor creates a new ShipProccessor that consumes the shipclient.Stream passed to it. func SpawnProccessor(shipStream *shipclient.Stream, loader StateLoader, saver StateSaver, writer driver.Writer, abi *abi.AbiManager, codec message.Codec) *ShipProcessor { processor := &ShipProcessor{ - saver: saver, - abi: abi, - shipStream: shipStream, - syscontract: chain.N("eosio"), - queue: NewMessageQueue(writer, codec.Encoder), + saver: saver, + abi: abi, + shipStream: shipStream, + syscontract: chain.N("eosio"), + queue: NewMessageQueue(writer, codec.Encoder), + postTransactions: true, + postActions: true, } loader(&processor.state) @@ -88,6 +96,14 @@ func (processor *ShipProcessor) SetTableDeltaWhitelist(list filter.List) { processor.tableDeltaWhitelist = list } +func (processor *ShipProcessor) SetPostTransactions(enabled bool) { + processor.postTransactions = enabled +} + +func (processor *ShipProcessor) SetPostActions(enabled bool) { + processor.postActions = enabled +} + func (processor *ShipProcessor) hasTableDeltaWhitelist() bool { return !processor.tableDeltaWhitelist.Empty() } @@ -203,16 +219,20 @@ func (processor *ShipProcessor) processTransactionTrace(log *log.Entry, blockNum actMsg.BlockNum = blockNumber actMsg.Timestamp = timestamp - if err := processor.queue.PostAction(*actMsg); err != nil { - logger.WithError(err).Error("Failed to post action trace") + if processor.postActions { + if err := processor.queue.PostAction(*actMsg); err != nil { + logger.WithError(err).Error("Failed to post action trace") + } } transaction.ActionTraces = append(transaction.ActionTraces, *actMsg) } } - if err := processor.queue.PostTransactionTrace(transaction); err != nil { - logger.WithError(err).Error("Failed to post transaction trace") + if processor.postTransactions { + if err := processor.queue.PostTransactionTrace(transaction); err != nil { + logger.WithError(err).Error("Failed to post transaction trace") + } } } diff --git a/internal/server/ship_processor_test.go b/internal/server/ship_processor_test.go index 26b724e..2d68024 100644 --- a/internal/server/ship_processor_test.go +++ b/internal/server/ship_processor_test.go @@ -77,3 +77,19 @@ func TestShipProcessor_FilterWhitelistedContractRows_NoWhitelist(t *testing.T) { require.Equal(t, rows, actual) } + +func TestShipProcessor_SetPostTransactions(t *testing.T) { + processor := &ShipProcessor{postTransactions: true} + + processor.SetPostTransactions(false) + + require.False(t, processor.postTransactions) +} + +func TestShipProcessor_SetPostActions(t *testing.T) { + processor := &ShipProcessor{postActions: true} + + processor.SetPostActions(false) + + require.False(t, processor.postActions) +}