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
const fn current_env() -> BuildEnv {
27
    if cfg!(feature = "runtime-benchmarks") {
28
        BuildEnv::Benchmark
29
    } else if cfg!(any(feature = "std", feature = "fast-runtime", test)) {
30
        BuildEnv::TestLike
31
    } else {
32
        BuildEnv::Prod
33
    }
34
}
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
pub const FULU_TEST_FORK_EPOCH: u64 = match current_env() {
45
    BuildEnv::Benchmark => 80000000001,
46
    _ => 5000000000,
47
};
48

            
49
// For tests, benchmarks and fast-runtime configurations we use the mocked fork versions
50
pub const fn fork_versions() -> ForkVersions {
51
    match current_env() {
52
        BuildEnv::Prod => ForkVersions {
53
            genesis: Fork {
54
                version: hex!("00000000"), // 0x00000000
55
                epoch: 0,
56
            },
57
            altair: Fork {
58
                version: hex!("01000000"), // 0x01000000
59
                epoch: 74240,
60
            },
61
            bellatrix: Fork {
62
                version: hex!("02000000"), // 0x02000000
63
                epoch: 144896,
64
            },
65
            capella: Fork {
66
                version: hex!("03000000"), // 0x03000000
67
                epoch: 194048,
68
            },
69
            deneb: Fork {
70
                version: hex!("04000000"), // 0x04000000
71
                epoch: 269568,
72
            },
73
            electra: Fork {
74
                version: hex!("05000000"), // 0x05000000
75
                epoch: 364032,
76
            },
77
            fulu: Fork {
78
                version: hex!("06000000"), // 0x06000000
79
                epoch: 411392,             // https://notes.ethereum.org/@bbusa/fusaka-bpo-timeline
80
            },
81
        },
82
        _ => ForkVersions {
83
            genesis: Fork {
84
                version: [0, 0, 0, 0],
85
                epoch: 0,
86
            },
87
            altair: Fork {
88
                version: [1, 0, 0, 0],
89
                epoch: 0,
90
            },
91
            bellatrix: Fork {
92
                version: [2, 0, 0, 0],
93
                epoch: 0,
94
            },
95
            capella: Fork {
96
                version: [3, 0, 0, 0],
97
                epoch: 0,
98
            },
99
            deneb: Fork {
100
                version: [4, 0, 0, 0],
101
                epoch: 0,
102
            },
103
            electra: Fork {
104
                version: [5, 0, 0, 0],
105
                epoch: ELECTRA_TEST_FORK_EPOCH,
106
            },
107
            fulu: Fork {
108
                version: [6, 0, 0, 0],
109
                epoch: FULU_TEST_FORK_EPOCH,
110
            },
111
        },
112
    }
113
}