Skip to content

Commit

Permalink
fixes after review.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristure committed Aug 6, 2024
1 parent 3379e9a commit 8169fac
Show file tree
Hide file tree
Showing 6 changed files with 936 additions and 956 deletions.
1,736 changes: 868 additions & 868 deletions data/hyperOutportBlocks/hyperOutportBlock.pb.go

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions data/hyperOutportBlocks/hyperOutportBlock.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ option go_package = "github.com/multiversx/mx-chain-ws-connector-firehose-go/dat
// TODO: move proto definition file in a shared space.

message HyperOutportBlock {
MetaOutportBlock MetaOutportBlock = 1;
repeated NotarizedHeaderOutportData NotarizedHeadersOutportData = 2;
MetaOutportBlock MetaOutportBlock = 1;
repeated NotarizedHeaderOutportData NotarizedHeadersOutportData = 2;
}

message NotarizedHeaderOutportData {
string NotarizedHeaderHash = 1;
ShardOutportBlock OutportBlock = 2;
string NotarizedHeaderHash = 1;
ShardOutportBlockV2 OutportBlock = 2;
}

message MetaOutportBlock {
Expand Down Expand Up @@ -92,10 +92,10 @@ message Header {
}

message MetaHeader {
uint64 Nonce = 1;
uint32 Epoch = 2;
uint64 Round = 3;
uint64 TimeStamp = 4;
uint64 Nonce = 1;
uint32 Epoch = 2;
uint64 Round = 3;
uint64 TimeStamp = 4;
repeated ShardData ShardInfo = 5;
repeated PeerData PeerInfo = 6;
bytes Signature = 7;
Expand Down
1 change: 1 addition & 0 deletions data/hyperOutportBlocks/shardOutportBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func (x *ShardOutportBlock) GetHeaderNonce() (uint64, error) {
return x.BlockData.Header.Nonce, nil
}

// GetHeaderNonce will return header nonce
func (y *ShardOutportBlockV2) GetHeaderNonce() (uint64, error) {
if y.BlockData == nil {
return 0, fmt.Errorf("shard outport block: nil block data")
Expand Down
3 changes: 3 additions & 0 deletions process/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ var ErrNilBlockServiceContext = errors.New("nil block service context")

// ErrInvalidValue signals that an invalid value was provded
var ErrInvalidValue = errors.New("invalid value provided")

// ErrNilBlockData signals than a block data is nil
var ErrNilBlockData = errors.New("nil block data")
103 changes: 53 additions & 50 deletions process/outportBlockConverter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (o *outportBlockConverter) HandleShardOutportBlockV2(outportBlock *outport.

func (o *outportBlockConverter) handleBlockData(blockData *outport.BlockData, shardOutportBlock *hyperOutportBlocks.ShardOutportBlockV2) error {
if blockData == nil {
return nil
return ErrNilBlockData
}

var miniBlocks []*hyperOutportBlocks.MiniBlock
Expand All @@ -93,16 +93,15 @@ func (o *outportBlockConverter) handleBlockData(blockData *outport.BlockData, sh
IntraShardMiniBlocks: intraShardMiniBlocks,
}

var err error
switch blockData.HeaderType {
case string(core.ShardHeaderV1):
err = o.handleHeaderV1(blockData.HeaderBytes, shardOutportBlock.BlockData)
err := o.handleHeaderV1(blockData.HeaderBytes, shardOutportBlock.BlockData)
if err != nil {
return fmt.Errorf("failed to handle header v1: %w", err)
}

case string(core.ShardHeaderV2):
err = o.handleHeaderV2(blockData.HeaderBytes, shardOutportBlock.BlockData)
err := o.handleHeaderV2(blockData.HeaderBytes, shardOutportBlock.BlockData)
if err != nil {
return fmt.Errorf("failed to handle header v2: %w", err)
}
Expand All @@ -121,9 +120,7 @@ func (o *outportBlockConverter) handleHeaderV1(headerBytes []byte, shardBlockDat
return fmt.Errorf("failed to unmarshal: %w", err)
}

shardBlockData.Header = &hyperOutportBlocks.Header{}
header := shardBlockData.Header

header := &hyperOutportBlocks.Header{}
header.Nonce = blockHeader.Nonce
header.PrevHash = blockHeader.PrevHash
header.PrevRandSeed = blockHeader.PrevRandSeed
Expand Down Expand Up @@ -183,6 +180,8 @@ func (o *outportBlockConverter) handleHeaderV1(headerBytes []byte, shardBlockDat
header.AccumulatedFees = accumulatedFees
header.DeveloperFees = developerFees

shardBlockData.Header = header

return nil
}

Expand All @@ -193,8 +192,7 @@ func (o *outportBlockConverter) handleHeaderV2(headerBytes []byte, shardBlockDat
return fmt.Errorf("failed to unmarshal: %w", err)
}

shardBlockData.Header = &hyperOutportBlocks.Header{}
header := shardBlockData.Header
header := &hyperOutportBlocks.Header{}
header.Nonce = blockHeader.Header.Nonce
header.PrevHash = blockHeader.Header.PrevHash
header.PrevRandSeed = blockHeader.Header.PrevRandSeed
Expand Down Expand Up @@ -267,6 +265,8 @@ func (o *outportBlockConverter) handleHeaderV2(headerBytes []byte, shardBlockDat
shardBlockData.ScheduledGasPenalized = blockHeader.ScheduledGasPenalized
shardBlockData.ScheduledGasRefunded = blockHeader.ScheduledGasRefunded

shardBlockData.Header = header

return nil
}

Expand Down Expand Up @@ -502,53 +502,56 @@ func (o *outportBlockConverter) copyTransactions(sourceTxs map[string]*outport.T
destTxInfo := &hyperOutportBlocks.TxInfoV2{}

// TxInfo - Transaction
if txInfo.Transaction != nil {
value, err := o.castBigInt(txInfo.Transaction.Value)
if err != nil {
return fmt.Errorf("failed to cast transaction [%s] value: %w", txHash, err)
}
if txInfo.Transaction == nil {
continue
}
value, err := o.castBigInt(txInfo.Transaction.Value)
if err != nil {
return fmt.Errorf("failed to cast transaction [%s] value: %w", txHash, err)
}

destTxInfo.Transaction = &hyperOutportBlocks.WrappedTx{
Nonce: txInfo.Transaction.Nonce,
Value: value,
RcvAddr: txInfo.Transaction.RcvAddr,
RcvUserName: txInfo.Transaction.RcvUserName,
SndAddr: txInfo.Transaction.SndAddr,
SndUserName: txInfo.Transaction.SndUserName,
GasPrice: txInfo.Transaction.GasPrice,
GasLimit: txInfo.Transaction.GasLimit,
Data: txInfo.Transaction.Data,
ChainID: txInfo.Transaction.ChainID,
Version: txInfo.Transaction.Version,
Signature: txInfo.Transaction.Signature,
Options: txInfo.Transaction.Options,
GuardianAddr: txInfo.Transaction.GuardianAddr,
GuardianSignature: txInfo.Transaction.GuardianSignature,
ExecutionOrder: txInfo.ExecutionOrder,
TxType: hyperOutportBlocks.TxType_UserTx,
}
destTxInfo.Transaction = &hyperOutportBlocks.WrappedTx{
Nonce: txInfo.Transaction.Nonce,
Value: value,
RcvAddr: txInfo.Transaction.RcvAddr,
RcvUserName: txInfo.Transaction.RcvUserName,
SndAddr: txInfo.Transaction.SndAddr,
SndUserName: txInfo.Transaction.SndUserName,
GasPrice: txInfo.Transaction.GasPrice,
GasLimit: txInfo.Transaction.GasLimit,
Data: txInfo.Transaction.Data,
ChainID: txInfo.Transaction.ChainID,
Version: txInfo.Transaction.Version,
Signature: txInfo.Transaction.Signature,
Options: txInfo.Transaction.Options,
GuardianAddr: txInfo.Transaction.GuardianAddr,
GuardianSignature: txInfo.Transaction.GuardianSignature,
ExecutionOrder: txInfo.ExecutionOrder,
TxType: hyperOutportBlocks.TxType_UserTx,
}

// TxInfo - FeeInfo
if txInfo.FeeInfo != nil {
fee, err := o.castBigInt(txInfo.FeeInfo.Fee)
if err != nil {
return fmt.Errorf("failed to cast transaction [%s] fee: %w", txHash, err)
}
// TxInfo - FeeInfo
if txInfo.FeeInfo == nil {
continue
}

initialPaidFee, err := o.castBigInt(txInfo.FeeInfo.InitialPaidFee)
if err != nil {
return fmt.Errorf("failed to cast transaction [%s] initial paid fee: %w", txHash, err)
}
fee, err := o.castBigInt(txInfo.FeeInfo.Fee)
if err != nil {
return fmt.Errorf("failed to cast transaction [%s] fee: %w", txHash, err)
}

destTxInfo.FeeInfo = &hyperOutportBlocks.FeeInfo{
GasUsed: txInfo.FeeInfo.GasUsed,
Fee: fee,
InitialPaidFee: initialPaidFee,
}
}
initialPaidFee, err := o.castBigInt(txInfo.FeeInfo.InitialPaidFee)
if err != nil {
return fmt.Errorf("failed to cast transaction [%s] initial paid fee: %w", txHash, err)
}

transactionPool.Transactions[txHash] = destTxInfo
destTxInfo.FeeInfo = &hyperOutportBlocks.FeeInfo{
GasUsed: txInfo.FeeInfo.GasUsed,
Fee: fee,
InitialPaidFee: initialPaidFee,
}

transactionPool.Transactions[txHash] = destTxInfo
}

return nil
Expand Down
33 changes: 3 additions & 30 deletions process/outportBlockConverter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ func TestOutportBlockConverter(t *testing.T) {
require.Nil(t, err)

shardOutportBlock, err := converter.HandleShardOutportBlockV2(ob)
if err != nil {
panic(err)
}
require.Nil(t, err)

header := &block.HeaderV2{}
err = gogoProtoMarshaller.Unmarshal(header, ob.BlockData.HeaderBytes)
Expand All @@ -95,9 +93,7 @@ func TestOutportBlockConverter_HandleShardOutportBlockV2(t *testing.T) {
require.Nil(t, err)

shardOutportBlock, err := converter.HandleShardOutportBlockV2(ob)
if err != nil {
panic(err)
}
require.Nil(t, err)

header := &block.Header{}
err = gogoProtoMarshaller.Unmarshal(header, ob.BlockData.HeaderBytes)
Expand All @@ -107,16 +103,6 @@ func TestOutportBlockConverter_HandleShardOutportBlockV2(t *testing.T) {
checkFieldsV2(t, ob, shardOutportBlock)
checkBlockData(t, ob.BlockData, shardOutportBlock.BlockData)

j, err := json.Marshal(shardOutportBlock)
if err != nil {
panic(err)
}

err = os.WriteFile("./shardoutport.json", j, 0655)
if err != nil {
panic(err)
}

jsonBytes, err = os.ReadFile(outportBlockHeaderV2JSONPath)
require.NoError(t, err, "failed to read test data")

Expand All @@ -128,9 +114,7 @@ func TestOutportBlockConverter_HandleShardOutportBlockV2(t *testing.T) {
require.Nil(t, err)

shardOutportBlock, err = converter.HandleShardOutportBlockV2(ob)
if err != nil {
panic(err)
}
require.Nil(t, err)

headerV2 := &block.HeaderV2{}
err = gogoProtoMarshaller.Unmarshal(headerV2, ob.BlockData.HeaderBytes)
Expand All @@ -139,17 +123,6 @@ func TestOutportBlockConverter_HandleShardOutportBlockV2(t *testing.T) {
checkHeaderV2ShardV2(t, headerV2, shardOutportBlock)
checkFieldsV2(t, ob, shardOutportBlock)
checkBlockData(t, ob.BlockData, shardOutportBlock.BlockData)

j, err = json.Marshal(shardOutportBlock)
if err != nil {
panic(err)
}

err = os.WriteFile("./shardoutpor2.json", j, 0655)
if err != nil {
panic(err)
}

}

func TestHeaderConverter(t *testing.T) {
Expand Down

0 comments on commit 8169fac

Please sign in to comment.