Skip to content

Commit

Permalink
Before Sirius, do not handle transferValueOnly events.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed Aug 26, 2024
1 parent 24a59d6 commit fec7822
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 49 deletions.
54 changes: 10 additions & 44 deletions server/services/transactionEventsController.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,61 +45,27 @@ func (controller *transactionEventsController) extractEventSCDeploy(tx *transact
}

func (controller *transactionEventsController) extractEventTransferValueOnly(tx *transaction.ApiTransactionResult) ([]*eventTransferValueOnly, error) {
isBeforeSirius := !controller.provider.IsReleaseSiriusActive(tx.Epoch)
if !controller.provider.IsReleaseSiriusActive(tx.Epoch) {
return make([]*eventTransferValueOnly, 0), nil
}

rawEvents := controller.findManyEventsByIdentifier(tx, transactionEventTransferValueOnly)
typedEvents := make([]*eventTransferValueOnly, 0)

for _, event := range rawEvents {
if isBeforeSirius {
typedEvent, err := controller.decideEffectiveEventTransferValueOnlyBeforeSirius(event)
if err != nil {
return nil, err
}

if typedEvent != nil {
typedEvents = append(typedEvents, typedEvent)
}
} else {
typedEvent, err := controller.decideEffectiveEventTransferValueOnlyAfterSirius(event)
if err != nil {
return nil, err
}
typedEvent, err := controller.decideEffectiveEventTransferValueOnlyAfterSirius(event)
if err != nil {
return nil, err
}

if typedEvent != nil {
typedEvents = append(typedEvents, typedEvent)
}
if typedEvent != nil {
typedEvents = append(typedEvents, typedEvent)
}
}

return typedEvents, nil
}

func (controller *transactionEventsController) decideEffectiveEventTransferValueOnlyBeforeSirius(event *transaction.Events) (*eventTransferValueOnly, error) {
numTopics := len(event.Topics)

if numTopics != numTopicsOfEventTransferValueOnlyBeforeSirius {
return nil, fmt.Errorf("%w: bad number of topics for 'transferValueOnly' = %d", errCannotRecognizeEvent, numTopics)
}

senderPubKey := event.Topics[0]
receiverPubKey := event.Topics[1]
valueBytes := event.Topics[2]

if len(valueBytes) == 0 {
return nil, nil
}

sender := controller.provider.ConvertPubKeyToAddress(senderPubKey)
receiver := controller.provider.ConvertPubKeyToAddress(receiverPubKey)
value := big.NewInt(0).SetBytes(valueBytes)

return &eventTransferValueOnly{
sender: sender,
receiver: receiver,
value: value.String(),
}, nil
}

// See: https://github.com/multiversx/mx-specs/blob/main/releases/protocol/release-specs-v1.6.0-Sirius.md#17-logs--events-changes-5490
func (controller *transactionEventsController) decideEffectiveEventTransferValueOnlyAfterSirius(event *transaction.Events) (*eventTransferValueOnly, error) {
numTopics := len(event.Topics)
Expand Down
7 changes: 2 additions & 5 deletions server/services/transactionEventsController_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestTransactionEventsController_ExtractEvents(t *testing.T) {
require.Equal(t, "erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6", events[0].deployerAddress)
})

t.Run("transferValueOnly, before Sirius", func(t *testing.T) {
t.Run("transferValueOnly, before Sirius (not handled at all)", func(t *testing.T) {
topic0 := testscommon.TestContractFooShard0.PubKey
topic1 := testscommon.TestContractBarShard0.PubKey
topic2 := big.NewInt(100).Bytes()
Expand All @@ -230,10 +230,7 @@ func TestTransactionEventsController_ExtractEvents(t *testing.T) {

events, err := controller.extractEventTransferValueOnly(tx)
require.NoError(t, err)
require.Len(t, events, 1)
require.Equal(t, testscommon.TestContractFooShard0.Address, events[0].sender)
require.Equal(t, testscommon.TestContractBarShard0.Address, events[0].receiver)
require.Equal(t, "100", events[0].value)
require.Len(t, events, 0)
})

t.Run("transferValueOnly, after Sirius, effective (intra-shard ExecuteOnDestContext)", func(t *testing.T) {
Expand Down

0 comments on commit fec7822

Please sign in to comment.