-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rian
committed
May 15, 2024
1 parent
0f24541
commit d3bda45
Showing
3 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package builder | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/NethermindEth/juno/core" | ||
"github.com/NethermindEth/juno/mempool" | ||
) | ||
|
||
// bootstrap submits transactions inside a block directly into the mempool | ||
// this allows us to bootstrap the network with unsupported transactions | ||
func (b *Builder) bootstrapChain() error { | ||
if b.starknetData == nil { | ||
return errors.New("can't bootstrap if the network isn't specified") | ||
} | ||
for i := 0; i < int(b.bootstrapToBlock); i++ { | ||
txns, err := getTxns(b, uint64(i)) | ||
if err != nil { | ||
return err | ||
} | ||
for _, txn := range txns { | ||
b.pool.Push(txn) | ||
} | ||
if err := b.Finalise(); err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func getTxns(builder *Builder, blockNumber uint64) ([]*mempool.BroadcastedTransaction, error) { | ||
var mempoolTxns []*mempool.BroadcastedTransaction | ||
block, err := builder.starknetData.BlockByNumber(context.Background(), blockNumber) | ||
if err != nil { | ||
return nil, err | ||
} | ||
txns := block.Transactions | ||
for _, txn := range txns { | ||
switch t := txn.(type) { | ||
case *core.DeployTransaction, *core.DeployAccountTransaction, *core.InvokeTransaction, *core.L1HandlerTransaction: | ||
mempoolTxns = append(mempoolTxns, | ||
&mempool.BroadcastedTransaction{ | ||
Transaction: t, | ||
}) | ||
case *core.DeclareTransaction: | ||
class, err := builder.starknetData.Class(context.Background(), t.ClassHash) | ||
if err != nil { | ||
return nil, err | ||
} | ||
mempoolTxns = append(mempoolTxns, &mempool.BroadcastedTransaction{ | ||
Transaction: t, | ||
DeclaredClass: class, | ||
}) | ||
default: | ||
return nil, errors.New("unknown transaction") | ||
} | ||
} | ||
return mempoolTxns, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters