-
Notifications
You must be signed in to change notification settings - Fork 7
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
[sovereign] Set outgoing miniblock slice with type in header #348
Open
mariusmihaic
wants to merge
14
commits into
MX-16438-update-bridge-outgoing-data
Choose a base branch
from
MX-16477-outgoing-miniblocks-with-type
base: MX-16438-update-bridge-outgoing-data
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f7dd448
FEAT: Change sov header with outgoing mb slice
mariusmihaic b2de4b5
FEAT: Outgoing mb type
mariusmihaic 5498b57
FIX: Import cycle outgoing mb
mariusmihaic 3624ad4
FIX: Simplify ShallowClone outgoing mb slice
mariusmihaic 47ba8e1
FIX: Typo
mariusmihaic c740cbf
CLN: Extend interface + typos
mariusmihaic d718ad5
FIX: Interface rename to be compatible in node
mariusmihaic 065d378
FIX: SetOutGoingMiniBlockHeaderHandler
mariusmihaic 8998ffb
FIX: Pointer receiver in OutGoingMiniBlockHeaders slice
mariusmihaic 74c60f4
FEAT: Unit tests outgoing mbs
mariusmihaic 9d2f461
CLN: General naming clearance
mariusmihaic afebfef
Merge branch 'feat/sovereign-cross-chain-validator-changes' into MX-1…
mariusmihaic ed860b2
Merge branch 'MX-16438-update-bridge-outgoing-data' into MX-16477-out…
mariusmihaic 319ecbe
FIX: Pointer receiver in sov chain ShallowClone
mariusmihaic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import ( | |
"math/big" | ||
|
||
"github.com/multiversx/mx-chain-core-go/core" | ||
"github.com/multiversx/mx-chain-core-go/core/check" | ||
"github.com/multiversx/mx-chain-core-go/data" | ||
"github.com/multiversx/mx-chain-core-go/data/headerVersionData" | ||
) | ||
|
@@ -33,23 +32,34 @@ func (sch *SovereignChainHeader) SetAdditionalData(_ headerVersionData.HeaderAdd | |
|
||
// ShallowClone returns a clone of the object | ||
func (sch *SovereignChainHeader) ShallowClone() data.HeaderHandler { | ||
if sch == nil || sch.Header == nil { | ||
if sch == nil { | ||
return nil | ||
} | ||
|
||
internalHeaderCopy := *sch.Header | ||
|
||
headerCopy := *sch | ||
headerCopy.Header = &internalHeaderCopy | ||
if len(sch.OutGoingMiniBlockHeaders) != 0 { | ||
headerCopy.OutGoingMiniBlockHeaders = copyOutGoingMBHeaders(sch.OutGoingMiniBlockHeaders) | ||
} | ||
|
||
if !check.IfNil(sch.OutGoingMiniBlockHeader) { | ||
internalOutGoingMbHeader := *sch.OutGoingMiniBlockHeader | ||
headerCopy.OutGoingMiniBlockHeader = &internalOutGoingMbHeader | ||
if sch.Header != nil { | ||
internalHeaderCopy := *sch.Header | ||
headerCopy.Header = &internalHeaderCopy | ||
} | ||
|
||
return &headerCopy | ||
} | ||
|
||
func copyOutGoingMBHeaders(outGoingMiniBlockHeaders []*OutGoingMiniBlockHeader) []*OutGoingMiniBlockHeader { | ||
ret := make([]*OutGoingMiniBlockHeader, len(outGoingMiniBlockHeaders)) | ||
|
||
for idx, outGoingMBHdr := range outGoingMiniBlockHeaders { | ||
copyMB := *outGoingMBHdr | ||
ret[idx] = ©MB | ||
} | ||
|
||
return ret | ||
} | ||
|
||
// GetShardID returns internal header shard id | ||
func (sch *SovereignChainHeader) GetShardID() uint32 { | ||
if sch == nil { | ||
|
@@ -549,33 +559,83 @@ func (sch *SovereignChainHeader) CheckFieldsForNil() error { | |
return nil | ||
} | ||
|
||
// GetOutGoingMiniBlockHeaderHandler returns the outgoing mini block header | ||
func (sch *SovereignChainHeader) GetOutGoingMiniBlockHeaderHandler() data.OutGoingMiniBlockHeaderHandler { | ||
// GetOutGoingMiniBlockHeaderHandlers returns the outgoing mini block headers | ||
func (sch *SovereignChainHeader) GetOutGoingMiniBlockHeaderHandlers() []data.OutGoingMiniBlockHeaderHandler { | ||
if sch == nil { | ||
return nil | ||
} | ||
|
||
return sch.GetOutGoingMiniBlockHeader() | ||
mbHeaders := sch.GetOutGoingMiniBlockHeaders() | ||
mbHeaderHandlers := make([]data.OutGoingMiniBlockHeaderHandler, len(mbHeaders)) | ||
|
||
for i := range mbHeaders { | ||
mbHeaderHandlers[i] = mbHeaders[i] | ||
} | ||
|
||
return mbHeaderHandlers | ||
} | ||
|
||
// SetOutGoingMiniBlockHeaderHandler returns the outgoing mini block header | ||
// GetOutGoingMiniBlockHeaderHandler returns the outgoing mb header with specified type, if found | ||
func (sch *SovereignChainHeader) GetOutGoingMiniBlockHeaderHandler(mbType int32) data.OutGoingMiniBlockHeaderHandler { | ||
if sch == nil { | ||
return nil | ||
} | ||
|
||
for _, outGoingMbHdr := range sch.OutGoingMiniBlockHeaders { | ||
if int32(outGoingMbHdr.Type) == mbType { | ||
return outGoingMbHdr | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// SetOutGoingMiniBlockHeaderHandler replaces the outgoing mb from the internal outgoing mb slice, if found. | ||
// Otherwise, it adds it add the end of the slice. | ||
func (sch *SovereignChainHeader) SetOutGoingMiniBlockHeaderHandler(mbHeader data.OutGoingMiniBlockHeaderHandler) error { | ||
if sch == nil { | ||
return data.ErrNilPointerReceiver | ||
} | ||
|
||
if check.IfNil(mbHeader) { | ||
sch.OutGoingMiniBlockHeader = nil | ||
return nil | ||
outGoingMbHdr := createOutGoingMbHeader(mbHeader) | ||
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. You deleted the |
||
for idx, currOutGoingMbHdr := range sch.OutGoingMiniBlockHeaders { | ||
if int32(currOutGoingMbHdr.Type) == mbHeader.GetOutGoingMBTypeInt32() { | ||
sch.OutGoingMiniBlockHeaders[idx] = outGoingMbHdr | ||
return nil | ||
} | ||
} | ||
|
||
sch.OutGoingMiniBlockHeader = &OutGoingMiniBlockHeader{ | ||
sch.OutGoingMiniBlockHeaders = append(sch.OutGoingMiniBlockHeaders, outGoingMbHdr) | ||
return nil | ||
} | ||
|
||
func createOutGoingMbHeader(mbHeader data.OutGoingMiniBlockHeaderHandler) *OutGoingMiniBlockHeader { | ||
return &OutGoingMiniBlockHeader{ | ||
Type: OutGoingMBType(mbHeader.GetOutGoingMBTypeInt32()), | ||
Hash: mbHeader.GetHash(), | ||
OutGoingOperationsHash: mbHeader.GetOutGoingOperationsHash(), | ||
AggregatedSignatureOutGoingOperations: mbHeader.GetAggregatedSignatureOutGoingOperations(), | ||
LeaderSignatureOutGoingOperations: mbHeader.GetLeaderSignatureOutGoingOperations(), | ||
} | ||
} | ||
|
||
// SetOutGoingMiniBlockHeaderHandlers sets the outgoing mini block headers | ||
func (sch *SovereignChainHeader) SetOutGoingMiniBlockHeaderHandlers(mbHeaders []data.OutGoingMiniBlockHeaderHandler) error { | ||
if sch == nil { | ||
return data.ErrNilPointerReceiver | ||
} | ||
|
||
if len(mbHeaders) == 0 { | ||
sch.OutGoingMiniBlockHeaders = nil | ||
return nil | ||
} | ||
|
||
miniBlockHeaders := make([]*OutGoingMiniBlockHeader, len(mbHeaders)) | ||
for i, mbHeaderHandler := range mbHeaders { | ||
miniBlockHeaders[i] = createOutGoingMbHeader(mbHeaderHandler) | ||
} | ||
|
||
sch.OutGoingMiniBlockHeaders = miniBlockHeaders | ||
return nil | ||
} | ||
|
||
|
@@ -725,6 +785,25 @@ func (omb *OutGoingMiniBlockHeader) SetAggregatedSignatureOutGoingOperations(sig | |
return nil | ||
} | ||
|
||
// GetOutGoingMBTypeInt32 returns the outgoing mb header type as int32 | ||
func (omb *OutGoingMiniBlockHeader) GetOutGoingMBTypeInt32() int32 { | ||
if omb == nil { | ||
return 0 | ||
} | ||
|
||
return int32(omb.Type) | ||
} | ||
|
||
// SetOutGoingMBTypeInt32 sets the mini block type | ||
func (omb *OutGoingMiniBlockHeader) SetOutGoingMBTypeInt32(mbType int32) error { | ||
if omb == nil { | ||
return data.ErrNilPointerReceiver | ||
} | ||
|
||
omb.Type = OutGoingMBType(mbType) | ||
return nil | ||
} | ||
|
||
// IsInterfaceNil checks if the underlying interface is nil | ||
func (omb *OutGoingMiniBlockHeader) IsInterfaceNil() bool { | ||
return omb == nil | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
... based on mb type ...