-
Notifications
You must be signed in to change notification settings - Fork 0
/
proposervm.go
64 lines (57 loc) · 1.87 KB
/
proposervm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (C) 2023, Lux Partners Limited. All rights reserved.
// See the file LICENSE for licensing terms.
package utils
import (
"context"
"crypto/ecdsa"
"math/big"
"github.com/luxdefi/subnet-evm/core/types"
"github.com/luxdefi/subnet-evm/ethclient"
"github.com/luxdefi/subnet-evm/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
)
const numTriggerTxs = 2 // Number of txs needed to activate the proposer VM fork
// IssueTxsToActivateProposerVMFork issues transactions at the current
// timestamp, which should be after the ProposerVM activation time (aka
// ApricotPhase4). This should generate a PostForkBlock because its parent block
// (genesis) has a timestamp (0) that is greater than or equal to the fork
// activation time of 0. Therefore, subsequent blocks should be built with
// BuildBlockWithContext.
func IssueTxsToActivateProposerVMFork(
ctx context.Context, chainID *big.Int, fundedKey *ecdsa.PrivateKey,
client ethclient.Client,
) error {
addr := crypto.PubkeyToAddress(fundedKey.PublicKey)
nonce, err := client.NonceAt(ctx, addr, nil)
if err != nil {
return err
}
newHeads := make(chan *types.Header, 1)
sub, err := client.SubscribeNewHead(ctx, newHeads)
if err != nil {
return err
}
defer sub.Unsubscribe()
gasPrice := big.NewInt(params.MinGasPrice)
txSigner := types.LatestSignerForChainID(chainID)
for i := 0; i < numTriggerTxs; i++ {
tx := types.NewTransaction(
nonce, addr, common.Big1, params.TxGas, gasPrice, nil)
triggerTx, err := types.SignTx(tx, txSigner, fundedKey)
if err != nil {
return err
}
if err := client.SendTransaction(ctx, triggerTx); err != nil {
return err
}
<-newHeads // wait for block to be accepted
nonce++
}
log.Info(
"Built sufficient blocks to activate proposerVM fork",
"txCount", numTriggerTxs,
)
return nil
}