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
32 changes: 29 additions & 3 deletions chunk_manager/chunk_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/AnomalyFi/Arcadia/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/sirupsen/logrus"
)

type ChunkLayer struct {
Expand All @@ -17,14 +18,17 @@ type ChunkLayer struct {

submittedToSEQ bool

l sync.RWMutex
logger *logrus.Entry
l sync.RWMutex
}

func NewChunkLayer(nonce uint64, tobChunk *ChunkWrapper) *ChunkLayer {
func NewChunkLayer(logger *logrus.Entry, nonce uint64, tobChunk *ChunkWrapper) *ChunkLayer {
logger = logger.WithField("nonce", nonce)
return &ChunkLayer{
tobNonce: nonce,
chunks: []*ChunkWrapper{tobChunk},
submittedToSEQ: false,
logger: logger,
}
}

Expand All @@ -35,7 +39,6 @@ func init() {
func (cl *ChunkLayer) ToBNonce() uint64 {
cl.l.RLock()
defer cl.l.RUnlock()

return cl.tobNonce
}

Expand Down Expand Up @@ -67,6 +70,7 @@ func (cl *ChunkLayer) Txs() (map[string]ethtypes.Transactions, error) {
func (cl *ChunkLayer) LowestBlockNumber() map[string]uint64 {
cl.l.RLock()
defer cl.l.RUnlock()

ret := make(map[string]uint64)
for _, chunk := range cl.chunks {
chunkBlockNumber := chunk.LowestBlockNumber()
Expand All @@ -86,6 +90,7 @@ func (cl *ChunkLayer) LowestBlockNumber() map[string]uint64 {
func (cl *ChunkLayer) TxsWithNewTob(tob *ChunkWrapper) (map[string]ethtypes.Transactions, error) {
cl.l.RLock()
defer cl.l.RUnlock()

ret := make(map[string]ethtypes.Transactions)
tobTxs, err := tob.Txs()
if err != nil {
Expand Down Expand Up @@ -117,6 +122,7 @@ func (cl *ChunkLayer) TxsWithNewTob(tob *ChunkWrapper) (map[string]ethtypes.Tran
func (cl *ChunkLayer) TxsWithNewRoB(rob *ChunkWrapper) (map[string]ethtypes.Transactions, error) {
cl.l.RLock()
defer cl.l.RUnlock()

robIdx := slices.IndexFunc(cl.chunks[1:], func(cw *ChunkWrapper) bool {
return cw.RoB.ChainID == rob.RoB.ChainID && cw.RoB.BlockNumber == rob.RoB.BlockNumber
})
Expand Down Expand Up @@ -161,6 +167,7 @@ func (cl *ChunkLayer) TxsWithNewRoB(rob *ChunkWrapper) (map[string]ethtypes.Tran
func (cl *ChunkLayer) PushChunk(chunk *ChunkWrapper) error {
cl.l.Lock()
defer cl.l.Unlock()

if chunk.ToB != nil {
return errors.New("trying to push tob into a chunk layer")
}
Expand All @@ -177,9 +184,13 @@ func (cl *ChunkLayer) PushChunk(chunk *ChunkWrapper) error {
return nil
}

// MarkChunkSubmittedToDA marks a chunk as submitted to DA by the ToBNonce and ChunkID, the assumption made here is
// - chunk layer exists at the tob nonce
// - chunkIDs are different in the same layer
func (cl *ChunkLayer) MarkChunkSubmittedToDA(msg *common.ArcadiaToSEQChunkMessage, cert *common.CertInfo) error {
cl.l.Lock()
defer cl.l.Unlock()

if cl.tobNonce != msg.Chunk.ToBNonce {
return fmt.Errorf("chunk tobNonce not match with chunk layer tobNonce")
}
Expand Down Expand Up @@ -213,8 +224,15 @@ func (cl *ChunkLayer) ChunksSubmittedToDA() bool {
cl.l.RLock()
defer cl.l.RUnlock()
submitted := true
cl.logger.Debugf("=======layer-%d da submission info", cl.tobNonce)
for _, chunk := range cl.chunks {
submitted = submitted && chunk.SubmittedToDA()
chunkID, err := chunk.ID()
if err != nil {
cl.logger.WithError(err).Debug("unable to get chunk id from chunk")
continue
}
cl.logger.Debugf("%s:%t", chunkID, chunk.SubmittedToDA())
}
return submitted
}
Expand All @@ -228,5 +246,13 @@ func (cl *ChunkLayer) LayerSubmittedToSEQ() bool {
func (cl *ChunkLayer) MarkLayerSubmittedToSEQ() {
cl.l.Lock()
defer cl.l.Unlock()

cl.submittedToSEQ = true
}

func (cl *ChunkLayer) Len() int {
cl.l.RLock()
defer cl.l.RUnlock()

return len(cl.chunks)
}
Loading