Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 14 additions & 1 deletion arcadia/arcadia.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
pathGetArcadiaBlock = "/api/arcadia/v1/validator/block" // validator requests arcadia block.
)

func NewArcadiaClient(url string, currEpoch uint64, currEpochBuilderPubKey *bls.PublicKey, availNs *[][]byte, vm VM) *Arcadia {

Check failure on line 83 in arcadia/arcadia.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

unused-parameter: parameter 'currEpochBuilderPubKey' seems to be unused, consider removing or renaming it as _ (revive)

Check failure on line 83 in arcadia/arcadia.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

unused-parameter: parameter 'availNs' seems to be unused, consider removing or renaming it as _ (revive)
url = strings.TrimRight(url, "/")

cli := &Arcadia{
Expand Down Expand Up @@ -238,7 +238,7 @@
if websocket.IsCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) ||
websocket.IsUnexpectedCloseError(err, websocket.CloseGoingAway, websocket.CloseAbnormalClosure) ||
strings.Contains(err.Error(), "close 1006") ||
strings.Contains(err.Error(), "use of closed network connection") {

Check failure on line 241 in arcadia/arcadia.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

empty-lines: extra empty line at the start of a block (revive)

Check failure on line 241 in arcadia/arcadia.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

unnecessary leading newline (whitespace)

cli.vm.Logger().Error("WebSocket connection closed", zap.Error(err))
// Attempt reconnect to arcadia.
Expand All @@ -252,7 +252,7 @@
}
cli.vm.Logger().Info("received message from arcadia", zap.Int("msgType", msgType), zap.String("rawMsg", string(rawMsg)))

if msgType == websocket.TextMessage {

Check failure on line 255 in arcadia/arcadia.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

early-return: if c { ... } else { ... continue } can be simplified to if !c { ... continue } ... (revive)
var newChunk ArcadiaToSEQChunkMessage
err := json.Unmarshal(rawMsg, &newChunk)
if err != nil {
Expand Down Expand Up @@ -585,17 +585,30 @@
MaxBandwidth: maxBw,
BlockNumber: blockNumber,
}
reqRaw, err := json.Marshal(reqr)
reqRaw, err := reqr.Payload()
if err != nil {
return nil, err
}

uwm, err := warp.NewUnsignedMessage(cli.vm.NetworkID(), cli.vm.ChainID(), reqRaw)
if err != nil {
return nil, err
}
sig, err := cli.vm.Sign(uwm)
if err != nil {
return nil, err
}
sigStr := hexutil.Encode(sig)

cli.vm.Logger().Debug("signing GetArcadiaBlock request with", zap.String("pubkey", hexutil.Encode(cli.vm.Signer().Compress())), zap.Uint64("height", blockNumber), zap.String("chainID", cli.vm.ChainID().String()), zap.Uint32("networkID", cli.vm.NetworkID()))

req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(reqRaw))
if err != nil {
return nil, err
}

req.Header.Set("Content-Type", "application/json")
req.Header.Set(GetArcadiaBlockSignatureHeader, sigStr)

resp, err := client.Do(req)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions arcadia/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ package arcadia
var DefaultNMTNamespace = make([]byte, 8)

const DefaultBuilderLRUSize = 20
const GetArcadiaBlockSignatureHeader = "X-Arcadia-GetBlock-Sig"
6 changes: 6 additions & 0 deletions arcadia/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package arcadia

import (
"encoding/json"

"github.com/ava-labs/avalanchego/ids"
"github.com/bits-and-blooms/bitset"

Expand Down Expand Up @@ -69,6 +71,10 @@ type GetBlockPayloadFromArcadia struct {
BlockNumber uint64 `json:"blockNumber"`
}

func (req *GetBlockPayloadFromArcadia) Payload() ([]byte, error) {
return json.Marshal(req)
}

type ChunkInterface interface {
Marshal() ([]byte, error)
Transactions() []*chain.Transaction
Expand Down
4 changes: 3 additions & 1 deletion arcadia/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
buf := bytes.NewBuffer(chunk.RemovedBitSet)
_, err := bs.ReadFrom(buf)
if err != nil {
return fmt.Errorf("unable to parse remove bitset, raw: %+v, err: %s", chunk.removedBitSet, err)

Check failure on line 37 in arcadia/utils.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}
chunk.removedBitSet = *bs
return nil
Expand All @@ -43,7 +43,7 @@
for _, tx := range chunk.Chunk.RoB.Txs {
_, stx, err := chain.UnmarshalTxs(tx, 1, actionReg, authReg)
if err != nil {
return fmt.Errorf("unable to unmarshal txs")

Check failure on line 46 in arcadia/utils.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

string-format: no format directive, use errors.New instead (revive)

Check failure on line 46 in arcadia/utils.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

fmt.Errorf can be replaced with errors.New (perfsprint)
}
if len(stx) == 0 {
return ErrNoTxsInRoB
Expand All @@ -58,7 +58,7 @@
buf := bytes.NewBuffer(chunk.RemovedBitSet)
_, err := bs.ReadFrom(buf)
if err != nil {
return fmt.Errorf("unable to parse remove bitset, raw: %+v, err: %s", chunk.removedBitSet, err)

Check failure on line 61 in arcadia/utils.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
}
chunk.removedBitSet = *bs
}
Expand Down Expand Up @@ -97,7 +97,9 @@
}

func namespaceToChainIDStr(ns []byte) string {
chainIDu64 := binary.LittleEndian.Uint64(ns)
nsPadded := make([]byte, 8)
copy(nsPadded[:], ns)

Check failure on line 101 in arcadia/utils.go

View workflow job for this annotation

GitHub Actions / hypersdk-lint

unslice: could simplify nsPadded[:] to nsPadded (gocritic)
chainIDu64 := binary.LittleEndian.Uint64(nsPadded)
chainID := big.NewInt(int64(chainIDu64))

return hexutil.EncodeBig(chainID)
Expand Down
Loading