1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-11-29 08:26:45 +01:00

ship: add action and transaction posting toggles

This commit is contained in:
Henrik Hautakoski 2026-08-28 14:10:32 +02:00
parent e107eae02e
commit 3d26a3e821
8 changed files with 69 additions and 9 deletions

View file

@ -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

View file

@ -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.

View file

@ -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",
},

View file

@ -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"},

View file

@ -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")

View file

@ -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"`
}

View file

@ -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")
}
}
}

View file

@ -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)
}