diff --git a/core/atomic/flag.go b/core/atomic/flag.go index f31ec4c19..daca6d4fe 100644 --- a/core/atomic/flag.go +++ b/core/atomic/flag.go @@ -7,14 +7,14 @@ type Flag struct { value uint32 } -// Set sets flag and returns its previous value -func (flag *Flag) Set() bool { +// SetReturningPrevious sets flag and returns its previous value +func (flag *Flag) SetReturningPrevious() bool { previousValue := atomic.SwapUint32(&flag.value, 1) return previousValue == 1 } -// Unset sets flag -func (flag *Flag) Unset() { +// Reset resets the flag, putting it in off position +func (flag *Flag) Reset() { atomic.StoreUint32(&flag.value, 0) } @@ -24,11 +24,11 @@ func (flag *Flag) IsSet() bool { return value == 1 } -// Toggle toggles the flag -func (flag *Flag) Toggle(set bool) { - if set { - flag.Set() +// SetValue sets the new value in the flag +func (flag *Flag) SetValue(newValue bool) { + if newValue { + _ = flag.SetReturningPrevious() } else { - flag.Unset() + flag.Reset() } } diff --git a/core/atomic/flag_test.go b/core/atomic/flag_test.go index ec4a4212c..1b216e5df 100644 --- a/core/atomic/flag_test.go +++ b/core/atomic/flag_test.go @@ -8,6 +8,8 @@ import ( ) func TestFlag_Set(t *testing.T) { + t.Parallel() + var flag Flag var wg sync.WaitGroup @@ -16,12 +18,12 @@ func TestFlag_Set(t *testing.T) { wg.Add(2) go func() { - flag.Set() + _ = flag.SetReturningPrevious() wg.Done() }() go func() { - flag.Set() + _ = flag.SetReturningPrevious() wg.Done() }() @@ -29,22 +31,24 @@ func TestFlag_Set(t *testing.T) { require.True(t, flag.IsSet()) } -func TestFlag_Unset(t *testing.T) { +func TestFlag_Reset(t *testing.T) { + t.Parallel() + var flag Flag var wg sync.WaitGroup - flag.Set() + _ = flag.SetReturningPrevious() require.True(t, flag.IsSet()) wg.Add(2) go func() { - flag.Unset() + flag.Reset() wg.Done() }() go func() { - flag.Unset() + flag.Reset() wg.Done() }() @@ -52,7 +56,9 @@ func TestFlag_Unset(t *testing.T) { require.False(t, flag.IsSet()) } -func TestFlag_Toggle(t *testing.T) { +func TestFlag_SetValue(t *testing.T) { + t.Parallel() + var flag Flag var wg sync.WaitGroup @@ -60,12 +66,12 @@ func TestFlag_Toggle(t *testing.T) { wg.Add(2) go func() { - flag.Toggle(true) + flag.SetValue(true) wg.Done() }() go func() { - flag.Toggle(true) + flag.SetValue(true) wg.Done() }() @@ -76,12 +82,12 @@ func TestFlag_Toggle(t *testing.T) { wg.Add(2) go func() { - flag.Toggle(false) + flag.SetValue(false) wg.Done() }() go func() { - flag.Toggle(false) + flag.SetValue(false) wg.Done() }() diff --git a/data/indexer/dtos.go b/data/indexer/dtos.go index 92af894d2..a9337fc60 100644 --- a/data/indexer/dtos.go +++ b/data/indexer/dtos.go @@ -32,7 +32,7 @@ type Pool struct { Rewards map[string]data.TransactionHandler Invalid map[string]data.TransactionHandler Receipts map[string]data.TransactionHandler - Logs map[string]data.LogHandler + Logs []*data.LogData } // ValidatorRatingInfo is a structure containing validator rating information diff --git a/data/types.go b/data/types.go new file mode 100644 index 000000000..52a6b0d7e --- /dev/null +++ b/data/types.go @@ -0,0 +1,7 @@ +package data + +// LogData holds the data needed for indexing logs and events +type LogData struct { + LogHandler + TxHash string +}