Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
c11084d
get arcadia block with signature verification
bianyuanop Feb 6, 2025
7973778
Merge pull request #63 from AnomalyFi/proposer-guard
bianyuanop Feb 14, 2025
452af1f
tob filtering if no rob
NateAtNodeKit Feb 14, 2025
05f2d84
debugging tests
rtavarezz Feb 14, 2025
d0ca9ed
updates
NateAtNodeKit Feb 14, 2025
3290af5
debugging failing test
rtavarezz Feb 16, 2025
d164b15
update
NateAtNodeKit Feb 17, 2025
1830cb9
base nonce fixed but fails at SimBlock call
rtavarezz Feb 17, 2025
06b9d6a
quick nonce fix & checkpoint for debugging
rtavarezz Feb 17, 2025
a8212dd
progress, still debugging tests. len txs mismatch.
rtavarezz Feb 18, 2025
03810b2
add txs hash stability test
NateAtNodeKit Feb 18, 2025
5e26f6c
tob base case passes! added rob submission for tob
rtavarezz Feb 18, 2025
49bdb7a
added tob bundle filtering logic
rtavarezz Feb 18, 2025
2b24e43
update tob filtering
NateAtNodeKit Feb 19, 2025
c853ea5
tob filtering updates
NateAtNodeKit Feb 19, 2025
da9d8e0
tobnonce test wip
NateAtNodeKit Feb 19, 2025
1b6651e
debugging failing tests checkpoint
rtavarezz Feb 20, 2025
e3905a2
tobstate update
NateAtNodeKit Feb 20, 2025
0eaa3cc
fix TestToBNonceState
bianyuanop Feb 20, 2025
e2673f3
adding new test logic to failing test cases
rtavarezz Feb 20, 2025
4ca0976
overall basic flow updates
NateAtNodeKit Feb 20, 2025
48e4602
fix overall test
NateAtNodeKit Feb 21, 2025
28879ec
fix null payload resp case in mockdb
NateAtNodeKit Feb 21, 2025
97fdb9e
update
NateAtNodeKit Feb 21, 2025
2b6d21c
update
NateAtNodeKit Feb 21, 2025
650ae2b
tx simulation allowed revert
NateAtNodeKit Feb 21, 2025
2d70fe5
working on submit new block req test cases
rtavarezz Feb 21, 2025
f75a3cc
fix incoming RoB conflicts with previous ToB, disallowed simulation r…
bianyuanop Feb 21, 2025
c631ea0
debugging last 2 failing cases, checkpoint.
rtavarezz Feb 22, 2025
55dcc7a
updates
NateAtNodeKit Feb 24, 2025
0b03c80
update
rtavarezz Feb 24, 2025
ae7b461
feedback comment
rtavarezz Feb 24, 2025
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
35 changes: 34 additions & 1 deletion common/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,45 @@ func DisplayEthTxs(txs map[string]ethtypes.Transactions) {
for domain, domainTxs := range txs {
fmt.Printf("domain: %s\n", domain)
for _, tx := range domainTxs {
fmt.Printf("tx: %s\n", tx.Hash().Hex())
sender, err := ExtractSender(tx)
if err != nil {
panic(err)
}
fmt.Printf("sender: %s tx: %s:%d\n", sender, tx.Hash().Hex(), tx.Nonce())
}
}
fmt.Printf("========txs info end=======\n")
}

func FindTxHash(txLhs *ethtypes.Transaction, txs []*ethtypes.Transaction) bool {
if txLhs == nil {
panic("txLhs is nil")
}
lhsHash := txLhs.Hash()
for _, tx := range txs {
rhsHash := tx.Hash()
if lhsHash == rhsHash {
return true
}
}
return false
}

func TxsHashUnorderedMatch(txsLhs []*ethtypes.Transaction, txsRhs []*ethtypes.Transaction) bool {
if len(txsLhs) != len(txsRhs) {
return false
}

for _, tx := range txsLhs {
if !FindTxHash(tx, txsRhs) {
fmt.Printf("could not find tx hash " + tx.Hash().Hex())
return false
}
}

return true
}

func SyncMapLen(m *sync.Map) int {
var length int
m.Range(func(_, _ interface{}) bool {
Expand Down
81 changes: 75 additions & 6 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 @@ -204,10 +205,12 @@ type ToBChunk struct {
txHash2BundleHash map[string]string
revertingTxHashes map[string]struct{}

// refers to whether bundle at idx has been removed
removedBitSet *bitset.BitSet
domains map[string]struct{} // chain ids or rollup ids
seqTxs []*chain.Transaction
initialized bool

domains map[string]struct{} // chain ids or rollup ids
seqTxs []*chain.Transaction
initialized bool

l sync.RWMutex
}
Expand All @@ -228,6 +231,17 @@ func (tob *ToBChunk) GetBundles() []*CrossRollupBundle {
return ret
}

func (tob *ToBChunk) IsBundleIdxFiltered(idx int) bool {
tob.l.RLock()
defer tob.l.RUnlock()

if idx >= len(tob.Bundles) {
return false
}

return tob.removedBitSet.Test(uint(idx))
}

func (tob *ToBChunk) GetTxs() map[string]ethtypes.Transactions {
tob.l.RLock()
defer tob.l.RUnlock()
Expand Down Expand Up @@ -343,10 +357,45 @@ func (tob *ToBChunk) removeBundleContainTx(txHash string) (*CrossRollupBundle, e
bundleIdx2remove := slices.IndexFunc(tob.Bundles, func(crb *CrossRollupBundle) bool {
return crb.BundleHash == bundleHash
})

// mark as removed
tob.removedBitSet = tob.removedBitSet.Set(uint(bundleIdx2remove))

// re-populate [tob.txs]
tob.repopulateToBTxs()

return tob.Bundles[bundleIdx2remove], nil
}

func (tob *ToBChunk) FilterBundleWithHash(bundleHash string) (*CrossRollupBundle, error) {
tob.l.Lock()
defer tob.l.Unlock()

var foundIdx int
var foundBundle *CrossRollupBundle

for bundleIdx, bundle := range tob.Bundles {
if bundle.BundleHash == bundleHash {
foundIdx = bundleIdx
foundBundle = bundle
break
}
}

if foundBundle == nil {
return nil, fmt.Errorf("filterBundleWithHash found no bundle hash [%s]", bundleHash)
}

// mark as removed
tob.removedBitSet = tob.removedBitSet.Set(uint(foundIdx))

// re-populate [tob.txs]
tob.repopulateToBTxs()

return tob.Bundles[foundIdx], nil
}

func (tob *ToBChunk) repopulateToBTxs() {
tob.txs = make(map[string]ethtypes.Transactions)
for bundleIdx, bundle := range tob.Bundles {
// continue as this bundle was removed
Expand All @@ -359,13 +408,12 @@ func (tob *ToBChunk) removeBundleContainTx(txHash string) (*CrossRollupBundle, e
tob.txs[domain] = l
}
}

// track domains that contain txs in it
tob.domains = make(map[string]struct{})
for domain := range tob.txs {
tob.domains[domain] = struct{}{}
}

return tob.Bundles[bundleIdx2remove], nil
}

// LowestBlockNumber return the tracked lowest heights for domains, this prevents the situation that
Expand Down Expand Up @@ -526,7 +574,7 @@ type RoBChunk struct {
BlockNumber uint64 `json:"block_number"`

// following fields will be populated after initialization
removedBitSet *bitset.BitSet
removedBitSet *bitset.BitSet // refers to whether tx within txs at idx has been removed
initialized bool
txs ethtypes.Transactions
seqTxs []*chain.Transaction
Expand Down Expand Up @@ -1135,6 +1183,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 Expand Up @@ -1505,6 +1570,10 @@ func (b *CrossRollupBundle) Domains() []string {
return maps.Keys(b.txs)
}

func (b *CrossRollupBundle) HasTxs() bool {
return len(b.txs) > 0
}

func (b *CrossRollupBundle) ContainTx(txHash string) bool {
for _, txs := range b.txs {
contain := slices.ContainsFunc(txs, func(t *ethtypes.Transaction) bool {
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)
}
11 changes: 6 additions & 5 deletions database/mockdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type MockDB struct {
RoBChunkMap map[string]map[uint64]*common.RoBChunkDB
RoBChunkAcceptedMap map[string]*common.RoBChunkAcceptedDB
LastFetchedBlockNum common.LastFetchedBlockNumberDB
PayloadResp common.PayloadDB
PayloadResp *common.PayloadDB
Epoch uint64
EpochLowestToBNonce map[uint64]uint64
PayloadTxsToB map[string]*common.PayloadTxs
Expand All @@ -54,7 +54,6 @@ func NewMockDB() *MockDB {
RoBChunkMap: make(map[string]map[uint64]*common.RoBChunkDB),
RoBChunkAcceptedMap: make(map[string]*common.RoBChunkAcceptedDB),
LastFetchedBlockNum: common.LastFetchedBlockNumberDB{},
PayloadResp: common.PayloadDB{},
Epoch: 0,
EpochLowestToBNonce: make(map[uint64]uint64),
PayloadTxsToB: make(map[string]*common.PayloadTxs),
Expand Down Expand Up @@ -247,8 +246,10 @@ func (db *MockDB) RemoveBestAuctionBid(epoch uint64) error {
func (db *MockDB) GetPayloadResp(chainID string, blockNumber uint64) (*common.PayloadDB, error) {
db.l.Lock()
defer db.l.Unlock()

return &db.PayloadResp, nil
if db.PayloadResp == nil {
return nil, nil
}
return db.PayloadResp, nil
}

func (db *MockDB) SetPayloadResp(chainID string, blockNumber uint64, txs *common.GetPayloadResponse) error {
Expand All @@ -260,7 +261,7 @@ func (db *MockDB) SetPayloadResp(chainID string, blockNumber uint64, txs *common
return err
}

db.PayloadResp = *payloadTxs
db.PayloadResp = payloadTxs
return nil
}

Expand Down
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"
Loading