-
Notifications
You must be signed in to change notification settings - Fork 205
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
Fixes outport refactor #5135
Fixes outport refactor #5135
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ import ( | |
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/core/check" | ||
"github.com/multiversx/mx-chain-core-go/core/unmarshal" | ||
"github.com/multiversx/mx-chain-core-go/data" | ||
"github.com/multiversx/mx-chain-core-go/data/block" | ||
"github.com/multiversx/mx-chain-core-go/data/outport" | ||
"github.com/multiversx/mx-chain-core-go/marshal" | ||
logger "github.com/multiversx/mx-chain-logger-go" | ||
|
@@ -29,8 +30,9 @@ type RevertBlock struct { | |
} | ||
|
||
type eventNotifier struct { | ||
httpClient httpClientHandler | ||
marshalizer marshal.Marshalizer | ||
httpClient httpClientHandler | ||
marshalizer marshal.Marshalizer | ||
blockContainer blockContainerHandler | ||
} | ||
|
||
// ArgsEventNotifier defines the arguments needed for event notifier creation | ||
|
@@ -46,10 +48,15 @@ func NewEventNotifier(args ArgsEventNotifier) (*eventNotifier, error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
blockContainer, err := createBlockCreatorsContainer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move it at the same level as factory: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &eventNotifier{ | ||
httpClient: args.HttpClient, | ||
marshalizer: args.Marshaller, | ||
httpClient: args.HttpClient, | ||
marshalizer: args.Marshaller, | ||
blockContainer: blockContainer, | ||
}, nil | ||
} | ||
|
||
|
@@ -78,7 +85,7 @@ func (en *eventNotifier) SaveBlock(args *outport.OutportBlock) error { | |
|
||
// RevertIndexedBlock converts revert data in order to be pushed to subscribers | ||
func (en *eventNotifier) RevertIndexedBlock(blockData *outport.BlockData) error { | ||
headerHandler, err := unmarshal.GetHeaderFromBytes(en.marshalizer, core.HeaderType(blockData.HeaderType), blockData.HeaderBytes) | ||
headerHandler, err := en.getHeaderFromBytes(core.HeaderType(blockData.HeaderType), blockData.HeaderBytes) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -142,3 +149,30 @@ func (en *eventNotifier) IsInterfaceNil() bool { | |
func (en *eventNotifier) Close() error { | ||
return nil | ||
} | ||
|
||
func (en *eventNotifier) getHeaderFromBytes(headerType core.HeaderType, headerBytes []byte) (header data.HeaderHandler, err error) { | ||
creator, err := en.blockContainer.Get(headerType) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return block.GetHeaderFromBytes(en.marshalizer, creator, headerBytes) | ||
} | ||
|
||
func createBlockCreatorsContainer() (blockContainerHandler, error) { | ||
container := block.NewEmptyBlockCreatorsContainer() | ||
err := container.Add(core.ShardHeaderV1, block.NewEmptyHeaderCreator()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = container.Add(core.ShardHeaderV2, block.NewEmptyHeaderV2Creator()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = container.Add(core.MetaHeader, block.NewEmptyMetaBlockCreator()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return container, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
package notifier | ||
|
||
import ( | ||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/data/block" | ||
) | ||
|
||
type httpClientHandler interface { | ||
Post(route string, payload interface{}) error | ||
IsInterfaceNil() bool | ||
} | ||
|
||
// BlockContainerHandler defines what a block container should be able to do | ||
type blockContainerHandler interface { | ||
Get(headerType core.HeaderType) (block.EmptyBlockCreator, error) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,7 +173,7 @@ func (s *sorter) getInvalidTxsExecutedInCurrentBlock(scheduledMbsFromPreviousBlo | |
for _, hash := range mb.TxHashes { | ||
_, found := allScheduledTxs[string(hash)] | ||
if found { | ||
scheduledExecutedInvalidTxsHashesPrevBlock = append(scheduledExecutedInvalidTxsHashesPrevBlock, string(hash)) | ||
scheduledExecutedInvalidTxsHashesPrevBlock = append(scheduledExecutedInvalidTxsHashesPrevBlock, hex.EncodeToString(hash)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this still backward compatible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes is not a problem. because this part is used only in indexer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, did not noticed that the package was actually |
||
continue | ||
} | ||
invalidTxHashes = append(invalidTxHashes, hash) | ||
|
@@ -249,9 +249,10 @@ func getRewardsTxsFromMe(pool *outport.TransactionPool, blockBody *block.Body, h | |
func extractTxsFromMap(txsHashes [][]byte, txs map[string]*outport.TxInfo) ([]data.TxWithExecutionOrderHandler, error) { | ||
result := make([]data.TxWithExecutionOrderHandler, 0, len(txsHashes)) | ||
for _, txHash := range txsHashes { | ||
tx, found := txs[string(txHash)] | ||
txHashHex := hex.EncodeToString(txHash) | ||
tx, found := txs[txHashHex] | ||
if !found { | ||
return nil, fmt.Errorf("cannot find transaction in pool, txHash: %s", hex.EncodeToString(txHash)) | ||
return nil, fmt.Errorf("cannot find transaction in pool, txHash: %s", txHashHex) | ||
} | ||
result = append(result, tx) | ||
} | ||
|
@@ -262,9 +263,10 @@ func extractTxsFromMap(txsHashes [][]byte, txs map[string]*outport.TxInfo) ([]da | |
func extractSCRsFromMap(txsHashes [][]byte, scrs map[string]*outport.SCRInfo) ([]data.TxWithExecutionOrderHandler, error) { | ||
result := make([]data.TxWithExecutionOrderHandler, 0, len(txsHashes)) | ||
for _, txHash := range txsHashes { | ||
scr, found := scrs[string(txHash)] | ||
txHashHex := hex.EncodeToString(txHash) | ||
scr, found := scrs[txHashHex] | ||
if !found { | ||
return nil, fmt.Errorf("cannot find scr in pool, txHash: %s", hex.EncodeToString(txHash)) | ||
return nil, fmt.Errorf("cannot find scr in pool, txHash: %s", txHashHex) | ||
} | ||
result = append(result, scr) | ||
} | ||
|
@@ -275,9 +277,10 @@ func extractSCRsFromMap(txsHashes [][]byte, scrs map[string]*outport.SCRInfo) ([ | |
func extractRewardsFromMap(txsHashes [][]byte, rewards map[string]*outport.RewardInfo) ([]data.TxWithExecutionOrderHandler, error) { | ||
result := make([]data.TxWithExecutionOrderHandler, 0, len(txsHashes)) | ||
for _, txHash := range txsHashes { | ||
reward, found := rewards[string(txHash)] | ||
txHashHex := hex.EncodeToString(txHash) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we keep the hash in hex format? This degrades the performance of the node as the hex.EncodeToString is more CPU intensive than the regular cast to string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need the transaction hash hex-encoded in order can send it over to the WS. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, this does not degrade the performance of the validators as the code impacted is in |
||
reward, found := rewards[txHashHex] | ||
if !found { | ||
return nil, fmt.Errorf("cannot find reward in pool, txHash: %s", hex.EncodeToString(txHash)) | ||
return nil, fmt.Errorf("cannot find reward in pool, txHash: %s", txHashHex) | ||
} | ||
result = append(result, reward) | ||
} | ||
|
@@ -299,7 +302,8 @@ func extractExecutedTxHashes(mbIndex int, mbTxHashes [][]byte, header data.Heade | |
|
||
func extractAndPutScrsToDestinationMap(scrsHashes [][]byte, scrsMap map[string]*outport.SCRInfo, destinationMap map[string]data.TxWithExecutionOrderHandler) { | ||
for _, scrHash := range scrsHashes { | ||
scr, found := scrsMap[string(scrHash)] | ||
scrHashHex := hex.EncodeToString(scrHash) | ||
scr, found := scrsMap[scrHashHex] | ||
if !found { | ||
continue | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the latest commit hash
I think this should be
932a718276f65ff8f820720adf5e98c4cfdd3074
.Check here: multiversx/mx-chain-core-go#171
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed