Skip to content
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

adapt stdout to upstream changes #3

Merged
merged 6 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion factory/wsConnectorFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func createWsHost(wsMarshaller marshal.Marshalizer, cfg config.WebSocketConfig)
Mode: cfg.Mode,
RetryDurationInSec: int(cfg.RetryDuration),
BlockingAckOnError: cfg.BlockingAckOnError,
DropMessagesIfNoConnection: false,
DropMessagesIfNoConnection: cfg.DropMessagesIfNoConnection,
AcknowledgeTimeoutInSec: cfg.AcknowledgeTimeoutInSec,
Version: cfg.Version,
},
Expand Down
31 changes: 16 additions & 15 deletions process/firehoseDataProcessor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package process

import (
"encoding/base64"
"encoding/hex"
"fmt"

Expand All @@ -15,9 +16,8 @@ import (
var log = logger.GetOrCreate("firehose")

const (
firehosePrefix = "FIRE"
beginBlockPrefix = "BLOCK_BEGIN"
endBlockPrefix = "BLOCK_END"
firehosePrefix = "FIRE"
blockPrefix = "BLOCK"
)

type dataProcessor struct {
Expand Down Expand Up @@ -89,25 +89,26 @@ func (dp *dataProcessor) saveBlock(marshalledData []byte) error {

log.Info("firehose: saving block", "nonce", header.GetNonce(), "hash", outportBlock.BlockData.HeaderHash)

_, err = fmt.Fprintf(dp.writer, "%s %s %d\n",
firehosePrefix,
beginBlockPrefix,
header.GetNonce(),
)
if err != nil {
return fmt.Errorf("could not write %s prefix , err: %w", beginBlockPrefix, err)
blockNum := header.GetNonce()
parentNum := blockNum - 1
if blockNum == 0 {
parentNum = 0
}
encodedMarshalledData := base64.StdEncoding.EncodeToString(marshalledData)

_, err = fmt.Fprintf(dp.writer, "%s %s %d %s %d %x\n",
_, err = fmt.Fprintf(dp.writer, "%s %s %d %s %d %s %d %d %s\n",
firehosePrefix,
endBlockPrefix,
header.GetNonce(),
blockPrefix,
blockNum,
hex.EncodeToString(outportBlock.BlockData.HeaderHash),
parentNum,
hex.EncodeToString(header.GetPrevHash()),
outportBlock.HighestFinalBlockNonce,
header.GetTimeStamp(),
marshalledData,
encodedMarshalledData,
)
if err != nil {
return fmt.Errorf("could not write %s prefix , err: %w", endBlockPrefix, err)
return fmt.Errorf("could not write %s , err: %w", blockPrefix, err)
Copy link

@ssd04 ssd04 Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that we have only one entry line and there is just blockPrefix, i don't think it's useful anymore to have it into the error message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, will just propagate the error as it is

}

return nil
Expand Down
30 changes: 21 additions & 9 deletions process/firehoseDataProcessor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package process

import (
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -202,12 +203,12 @@ func TestFirehoseIndexer_SaveBlock(t *testing.T) {
require.True(t, strings.Contains(err.Error(), err1.Error()))

err = fi.ProcessPayload(outportBlockBytes, outportcore.TopicSaveBlock, 1)
require.True(t, strings.Contains(err.Error(), err2.Error()))
require.Nil(t, err)

err = fi.ProcessPayload(outportBlockBytes, outportcore.TopicSaveBlock, 1)
require.Nil(t, err)
require.True(t, errors.Is(err, err2))

require.Equal(t, 5, ioWriterCalledCt)
require.Equal(t, 3, ioWriterCalledCt)
})

t.Run("should work", func(t *testing.T) {
Expand All @@ -227,6 +228,8 @@ func TestFirehoseIndexer_SaveBlock(t *testing.T) {
HeaderBytes: headerBytes,
HeaderType: string(core.ShardHeaderV1),
},

HighestFinalBlockNonce: 0,
}
outportBlockBytes, err := protoMarshaller.Marshal(outportBlock)
require.Nil(t, err)
Expand All @@ -240,11 +243,21 @@ func TestFirehoseIndexer_SaveBlock(t *testing.T) {

switch ioWriterCalledCt {
case 0:
require.Equal(t, []byte("FIRE BLOCK_BEGIN 1\n"), p)
case 1:
require.Equal(t, []byte(fmt.Sprintf("FIRE BLOCK_END 1 %s 100 %x\n",
num := header.GetNonce()
parentNum := num - 1
libNum := parentNum
encodedMvxBlock := base64.StdEncoding.EncodeToString(outportBlockBytes)

require.Equal(t, []byte(fmt.Sprintf("%s %s %d %s %d %s %d %d %s\n",
firehosePrefix,
blockPrefix,
num,
hex.EncodeToString(outportBlock.BlockData.HeaderHash),
parentNum,
hex.EncodeToString(header.PrevHash),
outportBlockBytes)), p)
libNum,
header.TimeStamp,
encodedMvxBlock)), p)
default:
require.Fail(t, "should not write again")
}
Expand All @@ -256,9 +269,8 @@ func TestFirehoseIndexer_SaveBlock(t *testing.T) {

err = fi.ProcessPayload(outportBlockBytes, outportcore.TopicSaveBlock, 1)
require.Nil(t, err)
require.Equal(t, 2, ioWriterCalledCt)
require.Equal(t, 1, ioWriterCalledCt)
})

}

func TestFirehoseIndexer_NoOperationFunctions(t *testing.T) {
Expand Down
Loading