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
18 changes: 18 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/AnomalyFi/hypersdk/chain"
"github.com/AnomalyFi/hypersdk/codec"
abls "github.com/AnomalyFi/hypersdk/crypto/bls"
"github.com/AnomalyFi/hypersdk/utils"
"github.com/AnomalyFi/nodekit-seq/actions"
"github.com/ava-labs/avalanchego/ids"
Expand Down Expand Up @@ -1135,6 +1136,23 @@ type GetBlockPayloadFromArcadia struct {
BlockNumber uint64 `json:"blockNumber"`
}

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

func (req *GetBlockPayloadFromArcadia) VerifyIssuer(networkID uint32, seqChainID ids.ID, pk *abls.PublicKey, sig *abls.Signature) (bool, error) {
payload, err := req.Payload()
if err != nil {
return false, err
}
uwm, err := warp.NewUnsignedMessage(networkID, seqChainID, payload)
if err != nil {
return false, err
}
uwmBytes := uwm.Bytes()
return abls.Verify(uwmBytes, pk, sig), nil
}

type SEQTxWrapper struct {
Tx *chain.Transaction
Size int
Expand Down
13 changes: 13 additions & 0 deletions common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

abls "github.com/AnomalyFi/hypersdk/crypto/bls"
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/AnomalyFi/hypersdk/chain"
Expand Down Expand Up @@ -221,3 +222,15 @@ func BuildDACert(chunk *ArcadiaChunk, epoch uint64, certificate []byte) *seqtype
return robDA
}
}

func HeaderToSEQSignature(sigHeader string) (*abls.Signature, error) {
sigBytes, err := hexutil.Decode(sigHeader)
if err != nil {
return nil, err
}
return abls.SignatureFromBytes(sigBytes)
}

func BytesToSEQPubkey(pkBytes []byte) (*abls.PublicKey, error) {
return abls.PublicKeyFromBytes(pkBytes)
}
2 changes: 1 addition & 1 deletion datalayer/mocks/mock_IDASubmitter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions datastore/mocks/mock_IDatastore.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions seq/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package seq

const DefaultProposerLRUSize = 20
const GetArcadiaBlockSignatureHeader = "X-Arcadia-GetBlock-Sig"
79 changes: 69 additions & 10 deletions seq/mocks/mock_BaseSeqClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions seq/seqclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/AnomalyFi/nodekit-seq/auth"
"github.com/AnomalyFi/nodekit-seq/consts"
srpc "github.com/AnomalyFi/nodekit-seq/rpc"
avacache "github.com/ava-labs/avalanchego/cache"
"github.com/ava-labs/avalanchego/ids"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -55,6 +56,7 @@ type BaseSeqClient interface {

SubmitActions(ctx context.Context, action []chain.Action) (ids.ID, error)
GenerateTransaction(ctx context.Context, acts []chain.Action) (*chain.Transaction, error)
ProposerAtHeight(ctx context.Context, height uint64) (*hrpc.Validator, error)
}

var _ BaseSeqClient = (*SeqClient)(nil)
Expand All @@ -69,6 +71,7 @@ type SeqClient struct {
blockHead *chain.StatefulBlock
blockHeadL sync.RWMutex

proposerAtHeight *avacache.LRU[uint64, *hrpc.Validator]
currentValidators []*hrpc.Validator

// ETH Chain related
Expand Down Expand Up @@ -128,6 +131,9 @@ func NewSeqClient(config *SeqClientConfig) (*SeqClient, error) {
wsCli: wsCli,
signer: config.PrivateKey,

currentValidators: make([]*hrpc.Validator, 0),
proposerAtHeight: &avacache.LRU[uint64, *hrpc.Validator]{Size: DefaultProposerLRUSize},

Namespace: nil,

parser: parser,
Expand Down Expand Up @@ -180,6 +186,19 @@ func NewSeqClient(config *SeqClientConfig) (*SeqClient, error) {
client.logger.WithField("validatorPubkeys", validatorPubkeys).Debug("setting new validator set")
}

// query the proposer at height + 1
go func() {
proposer, err := client.hrpc.NextProposer(ctx, blk.Hght+1)
if err != nil {
client.logger.WithFields(logrus.Fields{
"seqHeight": blk.Hght,
"err": err,
}).Warn("unable to query the next proposer at height")
return
}
client.proposerAtHeight.Put(blk.Hght+1, proposer)
}()

// calculate total weight of current validators.
var totalWeight uint64
for _, val := range currVal {
Expand Down Expand Up @@ -366,3 +385,18 @@ func (s *SeqClient) GetRollupsValidAtEpoch(ctx context.Context, epoch uint64) ([
}
return seqRollups.Rollups, nil
}

func (s *SeqClient) ProposerAtHeight(ctx context.Context, height uint64) (*hrpc.Validator, error) {
proposer, exists := s.proposerAtHeight.Get(height)
if exists {
return proposer, nil
}

proposer, err := s.hrpc.NextProposer(ctx, height)
if err != nil {
return nil, err
}

s.proposerAtHeight.Put(height, proposer)
return proposer, nil
}
Loading