This repository was archived by the owner on Apr 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 7 files changed +26
-41
lines changed Expand file tree Collapse file tree 7 files changed +26
-41
lines changed Original file line number Diff line number Diff line change @@ -15,12 +15,6 @@ import (
1515 log "github.com/inconshreveable/log15"
1616)
1717
18- // All addresses on the C-Chain with > 2 transactions as of 1/15/22
19- // Hash: 0xccbf8e430b30d08b5b3342208781c40b373d1b5885c1903828f367230a2568da
20-
21- //go:embed airdrops/011522.json
22- var AirdropData []byte
23-
2418type Airdrop struct {
2519 // Address strings are hex-formatted common.Address
2620 Address common.Address `serialize:"true" json:"address"`
@@ -125,15 +119,15 @@ func (g *Genesis) Verify() error {
125119 return nil
126120}
127121
128- func (g * Genesis ) Load (db database.KeyValueWriter ) error {
122+ func (g * Genesis ) Load (db database.KeyValueWriter , airdropData [] byte ) error {
129123 if len (g .AirdropHash ) > 0 {
130- h := common .BytesToHash (crypto .Keccak256 (AirdropData )).Hex ()
124+ h := common .BytesToHash (crypto .Keccak256 (airdropData )).Hex ()
131125 if g .AirdropHash != h {
132126 return fmt .Errorf ("expected standard allocation %s but got %s" , g .AirdropHash , h )
133127 }
134128
135129 standardAllocation := []* Airdrop {}
136- if err := json .Unmarshal (AirdropData , & standardAllocation ); err != nil {
130+ if err := json .Unmarshal (airdropData , & standardAllocation ); err != nil {
137131 return err
138132 }
139133
@@ -158,7 +152,3 @@ func (g *Genesis) Load(db database.KeyValueWriter) error {
158152 }
159153 return nil
160154}
161-
162- func CleanAirdropData () {
163- AirdropData = nil
164- }
Original file line number Diff line number Diff line change @@ -60,12 +60,6 @@ func init() {
6060 - 1 ,
6161 "seconds per unit of fee that will be rewarded in a lifeline transaction" ,
6262 )
63- genesisCmd .PersistentFlags ().Int64Var (
64- & lifelineUnitReward ,
65- "lifeline-unit-reward" ,
66- - 1 ,
67- "seconds per unit of fee that will be rewarded in a lifeline transaction" ,
68- )
6963 genesisCmd .PersistentFlags ().StringVar (
7064 & airdropHash ,
7165 "airdrop-hash" ,
File renamed without changes.
Original file line number Diff line number Diff line change @@ -15,6 +15,12 @@ import (
1515 "github.com/spf13/cobra"
1616)
1717
18+ // All addresses on the C-Chain with > 2 transactions as of 1/15/22
19+ // Hash: 0xccbf8e430b30d08b5b3342208781c40b373d1b5885c1903828f367230a2568da
20+
21+ //go:embed airdrops/011522.json
22+ var AirdropData []byte
23+
1824func init () {
1925 log .Root ().SetHandler (log .LvlFilterHandler (log .LvlDebug , log .StreamHandler (os .Stderr , log .LogfmtFormat ())))
2026}
@@ -50,11 +56,14 @@ func runFunc(cmd *cobra.Command, args []string) error {
5056 plugin .Serve (& plugin.ServeConfig {
5157 HandshakeConfig : rpcchainvm .Handshake ,
5258 Plugins : map [string ]plugin.Plugin {
53- "vm" : rpcchainvm .New (& vm.VM {}),
59+ "vm" : rpcchainvm .New (& vm.VM {AirdropData : AirdropData }),
5460 },
5561
5662 // A non-nil value here enables gRPC serving for this plugin...
5763 GRPCServer : plugin .DefaultGRPCServer ,
5864 })
65+
66+ // Remove reference so VM can free when ready
67+ AirdropData = nil
5968 return nil
6069}
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
1010 "encoding/hex"
1111 "encoding/json"
1212 "flag"
13+ "fmt"
1314 "math/rand"
1415 "net/http/httptest"
1516 "strings"
@@ -130,13 +131,10 @@ var _ = ginkgo.BeforeSuite(func() {
130131 Address : sender ,
131132 Balance : 10000000 ,
132133 },
133- {
134- Address : sender2 ,
135- Balance : 10000000 ,
136- },
137134 }
138- genesis .AirdropHash = "0xccbf8e430b30d08b5b3342208781c40b373d1b5885c1903828f367230a2568da"
139- genesis .AirdropUnits = 100
135+ airdropData := []byte (fmt .Sprintf (`[{"address":"%s"}]` , sender2 ))
136+ genesis .AirdropHash = ecommon .BytesToHash (crypto .Keccak256 (airdropData )).Hex ()
137+ genesis .AirdropUnits = 1000000000
140138 genesisBytes , err = json .Marshal (genesis )
141139 gomega .Ω (err ).Should (gomega .BeNil ())
142140
@@ -157,13 +155,13 @@ var _ = ginkgo.BeforeSuite(func() {
157155 db := manager .NewMemDB (avago_version .CurrentDatabase )
158156
159157 // TODO: test appsender
160- v := & vm.VM {}
158+ v := & vm.VM {AirdropData : airdropData }
161159 err := v .Initialize (
162160 ctx ,
163161 db ,
164162 genesisBytes ,
165163 nil ,
166- [] byte ( `{"clearAirdropData":false}` ) ,
164+ nil ,
167165 toEngine ,
168166 nil ,
169167 app ,
Original file line number Diff line number Diff line change @@ -18,8 +18,6 @@ type Config struct {
1818
1919 MempoolSize int `serialize:"true" json:"mempoolSize"`
2020 ActivityCacheSize int `serialize:"true" json:"activityCacheSize"`
21-
22- ClearAirdropData bool `serialize:"true" json:"clearAirdropData"`
2321}
2422
2523func (c * Config ) SetDefaults () {
@@ -33,6 +31,4 @@ func (c *Config) SetDefaults() {
3331
3432 c .MempoolSize = 1024
3533 c .ActivityCacheSize = 128
36-
37- c .ClearAirdropData = true
3834}
Original file line number Diff line number Diff line change @@ -40,10 +40,11 @@ var (
4040)
4141
4242type VM struct {
43- ctx * snow.Context
44- db database.Database
45- config Config
46- genesis * chain.Genesis
43+ ctx * snow.Context
44+ db database.Database
45+ config Config
46+ genesis * chain.Genesis
47+ AirdropData []byte
4748
4849 bootstrapped bool
4950
@@ -173,7 +174,7 @@ func (vm *VM) Initialize(
173174 }
174175
175176 // Set Balances
176- if err := vm .genesis .Load (vm .db ); err != nil {
177+ if err := vm .genesis .Load (vm .db , vm . AirdropData ); err != nil {
177178 log .Error ("could not set genesis allocation" , "err" , err )
178179 return err
179180 }
@@ -186,10 +187,7 @@ func (vm *VM) Initialize(
186187 vm .preferred , vm .lastAccepted = gBlkID , genesisBlk
187188 log .Info ("initialized spacesvm from genesis" , "block" , gBlkID )
188189 }
189-
190- if vm .config .ClearAirdropData {
191- chain .CleanAirdropData ()
192- }
190+ vm .AirdropData = nil
193191
194192 go vm .builder .Build ()
195193 go vm .builder .Gossip ()
You can’t perform that action at this time.
0 commit comments