-
Notifications
You must be signed in to change notification settings - Fork 178
/
system.go
86 lines (72 loc) · 2.81 KB
/
system.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package blueprints
import (
_ "embed"
"fmt"
"github.com/onflow/flow-core-contracts/lib/go/templates"
"github.com/onflow/flow-go/fvm/systemcontracts"
"github.com/onflow/flow-go/model/flow"
)
const SystemChunkTransactionGasLimit = 100_000_000
// TODO (Ramtin) after changes to this method are merged into master move them here.
// systemChunkTransactionTemplate looks for the epoch and version beacon heartbeat resources
// and calls them.
//
//go:embed scripts/systemChunkTransactionTemplate.cdc
var systemChunkTransactionTemplate string
// SystemChunkTransaction creates and returns the transaction corresponding to the
// system chunk for the given chain.
func SystemChunkTransaction(chain flow.Chain) (*flow.TransactionBody, error) {
contracts, err := systemcontracts.SystemContractsForChain(chain.ChainID())
if err != nil {
return nil, fmt.Errorf("could not get system contracts for chain: %w", err)
}
// this is only true for testnet, sandboxnet and mainnet.
if contracts.Epoch.Address != chain.ServiceAddress() {
// Temporary workaround because the heartbeat resources need to be moved
// to the service account:
// - the system chunk will attempt to load both Epoch and VersionBeacon
// resources from either the service account or the staking account
// - the service account committee can then safely move the resources
// at any time
// - once the resources are moved, this workaround should be removed
// after version v0.31.0
return systemChunkTransactionDualAuthorizers(chain, contracts)
}
tx := flow.NewTransactionBody().
SetScript(
[]byte(templates.ReplaceAddresses(
systemChunkTransactionTemplate,
templates.Environment{
EpochAddress: contracts.Epoch.Address.Hex(),
NodeVersionBeaconAddress: contracts.NodeVersionBeacon.Address.Hex(),
},
)),
).
AddAuthorizer(contracts.Epoch.Address).
SetGasLimit(SystemChunkTransactionGasLimit)
return tx, nil
}
// systemChunkTransactionTemplateDualAuthorizer is the same as systemChunkTransactionTemplate
// but it looks for the heartbeat resources on two different accounts.
//
//go:embed scripts/systemChunkTransactionTemplateDualAuthorizer.cdc
var systemChunkTransactionTemplateDualAuthorizer string
func systemChunkTransactionDualAuthorizers(
chain flow.Chain,
contracts *systemcontracts.SystemContracts,
) (*flow.TransactionBody, error) {
tx := flow.NewTransactionBody().
SetScript(
[]byte(templates.ReplaceAddresses(
systemChunkTransactionTemplateDualAuthorizer,
templates.Environment{
EpochAddress: contracts.Epoch.Address.Hex(),
NodeVersionBeaconAddress: contracts.NodeVersionBeacon.Address.Hex(),
},
)),
).
AddAuthorizer(chain.ServiceAddress()).
AddAuthorizer(contracts.Epoch.Address).
SetGasLimit(SystemChunkTransactionGasLimit)
return tx, nil
}