1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
use hex_literal::hex;
18
use snowbridge_beacon_primitives::{Fork, ForkVersions};
19

            
20
enum BuildEnv {
21
    Prod,
22
    Benchmark,
23
    TestLike,
24
}
25

            
26
18
const fn current_env() -> BuildEnv {
27
18
    if cfg!(feature = "runtime-benchmarks") {
28
        BuildEnv::Benchmark
29
18
    } else if cfg!(any(feature = "std", feature = "fast-runtime", test)) {
30
18
        BuildEnv::TestLike
31
    } else {
32
        BuildEnv::Prod
33
    }
34
18
}
35

            
36
// Very stupid, but benchmarks are written assuming a fork epoch,
37
// and test vectors assuming another one
38
// We need allow dead code here because for regular builds this variable is not used
39
// This variable is only used in test, fast-runtime or runtime-benchmarks
40
pub const ELECTRA_TEST_FORK_EPOCH: u64 = match current_env() {
41
    BuildEnv::Benchmark => 80000000000,
42
    _ => 0,
43
};
44

            
45
// For tests, benchmarks and fast-runtime configurations we use the mocked fork versions
46
18
pub const fn fork_versions() -> ForkVersions {
47
18
    match current_env() {
48
        BuildEnv::Prod => ForkVersions {
49
            genesis: Fork {
50
                version: hex!("00000000"), // 0x00000000
51
                epoch: 0,
52
            },
53
            altair: Fork {
54
                version: hex!("01000000"), // 0x01000000
55
                epoch: 74240,
56
            },
57
            bellatrix: Fork {
58
                version: hex!("02000000"), // 0x02000000
59
                epoch: 144896,
60
            },
61
            capella: Fork {
62
                version: hex!("03000000"), // 0x03000000
63
                epoch: 194048,
64
            },
65
            deneb: Fork {
66
                version: hex!("04000000"), // 0x04000000
67
                epoch: 269568,
68
            },
69
            electra: Fork {
70
                version: hex!("05000000"), // 0x05000000
71
                epoch: 364032,
72
            },
73
        },
74
18
        _ => ForkVersions {
75
18
            genesis: Fork {
76
18
                version: [0, 0, 0, 0],
77
18
                epoch: 0,
78
18
            },
79
18
            altair: Fork {
80
18
                version: [1, 0, 0, 0],
81
18
                epoch: 0,
82
18
            },
83
18
            bellatrix: Fork {
84
18
                version: [2, 0, 0, 0],
85
18
                epoch: 0,
86
18
            },
87
18
            capella: Fork {
88
18
                version: [3, 0, 0, 0],
89
18
                epoch: 0,
90
18
            },
91
18
            deneb: Fork {
92
18
                version: [4, 0, 0, 0],
93
18
                epoch: 0,
94
18
            },
95
18
            electra: Fork {
96
18
                version: [5, 0, 0, 0],
97
18
                epoch: ELECTRA_TEST_FORK_EPOCH,
98
18
            },
99
18
        },
100
    }
101
18
}