Skip to content

Commit

Permalink
Merge branch 'feat/sovereign' into MX-15667-fix-epoch-start-pointer-r…
Browse files Browse the repository at this point in the history
…eceivers

# Conflicts:
#	data/block/sovereignChainHeader.go
  • Loading branch information
mariusmihaic committed Dec 9, 2024
2 parents 057bcad + 16e4df5 commit 25ee3bc
Show file tree
Hide file tree
Showing 18 changed files with 645 additions and 439 deletions.
11 changes: 10 additions & 1 deletion data/block/sovereignChainHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func (sch *SovereignChainHeader) SetAccumulatedFeesInEpoch(value *big.Int) error
return nil
}

// GetEpochStartHandler returns epoch start header handler as for metachain, but without last finalized headers
// GetEpochStartHandler returns epoch start header handler as for metachain, but with last finalized headers from main chain, if found.
func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler {
if sch == nil {
return nil
Expand All @@ -654,6 +654,15 @@ func (sch *SovereignChainHeader) GetEpochStartHandler() data.EpochStartHandler {
return &sch.EpochStart
}

// GetLastFinalizedCrossChainHeaderHandler returns the last finalized cross chain header data
func (sch *SovereignChainHeader) GetLastFinalizedCrossChainHeaderHandler() data.EpochStartChainDataHandler {
if sch == nil {
return nil
}

return &sch.EpochStart.LastFinalizedCrossChainHeader
}

// GetShardInfoHandlers returns empty slice
func (sch *SovereignChainHeader) GetShardInfoHandlers() []data.ShardDataHandler {
if sch == nil {
Expand Down
538 changes: 490 additions & 48 deletions data/block/sovereignChainHeader.pb.go

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion data/block/sovereignChainHeader.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ import "metaBlock.proto";

// EpochStart holds the block information for end-of-epoch
message EpochStartSovereign {
Economics Economics = 1 [(gogoproto.jsontag) = "economics", (gogoproto.nullable) = false];
Economics Economics = 1 [(gogoproto.jsontag) = "economics", (gogoproto.nullable) = false];
EpochStartCrossChainData LastFinalizedCrossChainHeader = 2 [(gogoproto.jsontag) = "lastFinalizedCrossChainHeader", (gogoproto.nullable) = false];
}

// EpochStartShardData hold the last finalized headers hash and state root hash
message EpochStartCrossChainData {
uint32 ShardID = 1 [(gogoproto.jsontag) = "shardID"];
uint32 Epoch = 9 [(gogoproto.jsontag) = "epoch"];
uint64 Round = 7 [(gogoproto.jsontag) = "round"];
uint64 Nonce = 8 [(gogoproto.jsontag) = "nonce"];
bytes HeaderHash = 2 [(gogoproto.jsontag) = "headerHash,omitempty"];
}

// SovereignChainHeader extends the Header structure with extra fields needed by sovereign chain
Expand Down
20 changes: 19 additions & 1 deletion data/esdt/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func IsValidPrefixedToken(token string) (string, bool) {
}

tokenRandSeq := tokenSplit[2]
if !(len(tokenRandSeq) >= esdtTickerNumRandChars) {
if !IsRandomSeqValid(tokenRandSeq) {
return "", false
}

Expand Down Expand Up @@ -83,3 +83,21 @@ func IsTickerValid(ticker string) bool {
func IsTokenTickerLenCorrect(tokenTickerLen int) bool {
return !(tokenTickerLen < minLengthForTickerName || tokenTickerLen > maxLengthForTickerName)
}

// IsRandomSeqValid checks if the token random sequence is valid
func IsRandomSeqValid(randomSeq string) bool {
if len(randomSeq) != esdtTickerNumRandChars {
return false
}

for _, ch := range randomSeq {
isSmallCharacter := ch >= 'a' && ch <= 'f'
isNumber := ch >= '0' && ch <= '9'
isReadable := isSmallCharacter || isNumber
if !isReadable {
return false
}
}

return true
}
10 changes: 5 additions & 5 deletions data/esdt/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ import (
)

func TestIsValidPrefixedToken(t *testing.T) {
prefix, valid := IsValidPrefixedToken("sov1-TKN-coffee")
prefix, valid := IsValidPrefixedToken("sov1-TKN-c0ffee")
require.True(t, valid)
require.Equal(t, "sov1", prefix)

prefix, valid = IsValidPrefixedToken("sOv1-TKN-coffee")
prefix, valid = IsValidPrefixedToken("sOv1-TKN-c0ffee")
require.False(t, valid)
require.Equal(t, "", prefix)

prefix, valid = IsValidPrefixedToken("sov1-TkN-coffee")
prefix, valid = IsValidPrefixedToken("sov1-TkN-c0ffee")
require.False(t, valid)
require.Equal(t, "", prefix)

prefix, valid = IsValidPrefixedToken("sov1-TKN-coffe")
prefix, valid = IsValidPrefixedToken("sov1-TKN-c0ffe")
require.False(t, valid)
require.Equal(t, "", prefix)

prefix, valid = IsValidPrefixedToken("sov1-TKN")
require.False(t, valid)
require.Equal(t, "", prefix)

prefix, valid = IsValidPrefixedToken("TKN-coffee")
prefix, valid = IsValidPrefixedToken("TKN-c0ffee")
require.False(t, valid)
require.Equal(t, "", prefix)
}
Expand Down
22 changes: 14 additions & 8 deletions data/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type SovereignChainHeaderHandler interface {
GetEpochStartHandler() EpochStartHandler
GetShardInfoHandlers() []ShardDataHandler
SetShardInfoHandlers(shardInfo []ShardDataHandler) error
GetLastFinalizedCrossChainHeaderHandler() EpochStartChainDataHandler
}

// OutGoingMiniBlockHeaderHandler defines setters and getters for sovereign outgoing mini block header
Expand Down Expand Up @@ -243,23 +244,30 @@ type ShardDataHandler interface {
ShallowClone() ShardDataHandler
}

// EpochStartShardDataHandler defines setters and getters for EpochStartShardData
type EpochStartShardDataHandler interface {
// EpochStartChainDataHandler defines setters and getters for basic information related to epoch start data
type EpochStartChainDataHandler interface {
GetShardID() uint32
GetEpoch() uint32
GetRound() uint64
GetNonce() uint64
GetHeaderHash() []byte
GetRootHash() []byte
GetFirstPendingMetaBlock() []byte
GetLastFinishedMetaBlock() []byte
GetPendingMiniBlockHeaderHandlers() []MiniBlockHeaderHandler

SetShardID(uint32) error
SetEpoch(uint32) error
SetRound(uint64) error
SetNonce(uint64) error
SetHeaderHash([]byte) error
}

// EpochStartShardDataHandler defines setters and getters for EpochStartShardData
type EpochStartShardDataHandler interface {
EpochStartChainDataHandler

GetRootHash() []byte
GetFirstPendingMetaBlock() []byte
GetLastFinishedMetaBlock() []byte
GetPendingMiniBlockHeaderHandlers() []MiniBlockHeaderHandler

SetRootHash([]byte) error
SetFirstPendingMetaBlock([]byte) error
SetLastFinishedMetaBlock([]byte) error
Expand Down Expand Up @@ -341,7 +349,6 @@ type TransactionHandler interface {
GetSndAddr() []byte
GetGasLimit() uint64
GetGasPrice() uint64
GetUserTransactions() []TransactionHandler

SetValue(*big.Int)
SetData([]byte)
Expand Down Expand Up @@ -468,7 +475,6 @@ type TransactionWithFeeHandler interface {
GetData() []byte
GetRcvAddr() []byte
GetValue() *big.Int
GetUserTransactions() []TransactionHandler
}

// UserAccountHandler models a user account
Expand Down
5 changes: 0 additions & 5 deletions data/receipt/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ func (_ *Receipt) GetRcvUserName() []byte {
return nil
}

// GetUserTransactions returns nil as Receipt does not have user transactions
func (rpt *Receipt) GetUserTransactions() []data.TransactionHandler {
return nil
}

// CheckIntegrity checks for not nil fields and negative value
func (rpt *Receipt) CheckIntegrity() error {
return nil
Expand Down
1 change: 0 additions & 1 deletion data/receipt/receipt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func TestReceipt_SettersAndGetters(t *testing.T) {
assert.Equal(t, uint64(0), r.GetNonce())
assert.Equal(t, uint64(0), r.GetGasPrice())
assert.Equal(t, uint64(0), r.GetGasLimit())
assert.Nil(t, r.GetUserTransactions())
}

func TestReceipt_CheckIntegrityReturnsNil(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions data/rewardTx/rewardTx.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ func (rtx *RewardTx) GetRcvUserName() []byte {
return nil
}

// GetUserTransactions returns nil as RewardTx does not have user transactions
func (rtx *RewardTx) GetUserTransactions() []data.TransactionHandler {
return nil
}

// CheckIntegrity checks for not nil fields and negative value
func (rtx *RewardTx) CheckIntegrity() error {
if len(rtx.RcvAddr) == 0 {
Expand Down
1 change: 0 additions & 1 deletion data/rewardTx/rewardTx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestRewardTx_GettersAndSetters(t *testing.T) {
assert.Equal(t, uint64(0), rwdTx.GetGasLimit())
assert.Equal(t, uint64(0), rwdTx.GetGasPrice())
assert.Equal(t, uint64(0), rwdTx.GetNonce())
assert.Nil(t, rwdTx.GetUserTransactions())
}

func TestRewardTx_CheckIntegrityShouldWork(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions data/smartContractResult/smartContractResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ func (_ *SmartContractResult) GetRcvUserName() []byte {
return nil
}

// GetUserTransactions returns nil as SmartContractResult does not have user transactions
func (scr *SmartContractResult) GetUserTransactions() []data.TransactionHandler {
return nil
}

// TrimSlicePtr creates a copy of the provided slice without the excess capacity
func TrimSlicePtr(in []*SmartContractResult) []*SmartContractResult {
if len(in) == 0 {
Expand Down
1 change: 0 additions & 1 deletion data/smartContractResult/smartContractResult_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestSmartContractResult_SettersAndGetters(t *testing.T) {
assert.Equal(t, gasLimit, scr.GetGasLimit())
assert.Equal(t, gasPrice, scr.GetGasPrice())
assert.Equal(t, nonce, scr.GetNonce())
assert.Nil(t, scr.GetUserTransactions())
}

func TestTrimSlicePtr(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion data/transaction/apiTransactionResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type ApiTransactionResult struct {
Options uint32 `json:"options"`
GuardianAddr string `json:"guardian,omitempty"`
GuardianSignature string `json:"guardianSignature,omitempty"`
InnerTransactions []*FrontendTransaction `json:"innerTransactions,omitempty"`
}

// ApiSmartContractResult represents a smart contract result with changed fields' types in order to make it friendly for API's json
Expand Down
32 changes: 15 additions & 17 deletions data/transaction/frontendTransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@ package transaction

// FrontendTransaction represents the DTO used in transaction signing/validation.
type FrontendTransaction struct {
Nonce uint64 `json:"nonce"`
Value string `json:"value"`
Receiver string `json:"receiver"`
Sender string `json:"sender"`
SenderUsername []byte `json:"senderUsername,omitempty"`
ReceiverUsername []byte `json:"receiverUsername,omitempty"`
GasPrice uint64 `json:"gasPrice"`
GasLimit uint64 `json:"gasLimit"`
Data []byte `json:"data,omitempty"`
Signature string `json:"signature,omitempty"`
ChainID string `json:"chainID"`
Version uint32 `json:"version"`
Options uint32 `json:"options,omitempty"`
GuardianAddr string `json:"guardian,omitempty"`
GuardianSignature string `json:"guardianSignature,omitempty"`
Relayer string `json:"relayer,omitempty"`
InnerTransactions []*FrontendTransaction `json:"innerTransactions,omitempty"`
Nonce uint64 `json:"nonce"`
Value string `json:"value"`
Receiver string `json:"receiver"`
Sender string `json:"sender"`
SenderUsername []byte `json:"senderUsername,omitempty"`
ReceiverUsername []byte `json:"receiverUsername,omitempty"`
GasPrice uint64 `json:"gasPrice"`
GasLimit uint64 `json:"gasLimit"`
Data []byte `json:"data,omitempty"`
Signature string `json:"signature,omitempty"`
ChainID string `json:"chainID"`
Version uint32 `json:"version"`
Options uint32 `json:"options,omitempty"`
GuardianAddr string `json:"guardian,omitempty"`
GuardianSignature string `json:"guardianSignature,omitempty"`
}
Loading

0 comments on commit 25ee3bc

Please sign in to comment.