From 5e1aa0ed343b6a471faeed3a08aa628f3bd7f73c Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Fri, 7 Jun 2019 05:37:21 +0000 Subject: [PATCH] [gensis] add separate files to handle different genesis module Signed-off-by: Leo Chen --- internal/genesis/foundational.go | 13 +++++ internal/genesis/genesis.go | 89 ++++++++++++++++++++++++++++++++ internal/genesis/genesis_test.go | 10 ++++ internal/genesis/newnodes.go | 15 ++++++ 4 files changed, 127 insertions(+) create mode 100644 internal/genesis/foundational.go create mode 100644 internal/genesis/genesis.go create mode 100644 internal/genesis/genesis_test.go create mode 100644 internal/genesis/newnodes.go diff --git a/internal/genesis/foundational.go b/internal/genesis/foundational.go new file mode 100644 index 000000000..5d130082e --- /dev/null +++ b/internal/genesis/foundational.go @@ -0,0 +1,13 @@ +package genesis + +// GenesisFNAccounts are the ECSDA accounts for the foundational nodes. +var GenesisFNAccounts = [...]DeployAccount{ + {Address: "0x007579ED2Fe889C5255C36d4978Ac94d25811771", Public: "0x007579ED2Fe889C5255C36d4978Ac94d25811771", BLSKey: "7053ea601630909e40ac03fe808a087594bd72b6fe5ddd5e5466826e0f8e1153"}, + {Address: "0x28dA1beF8F5361863DcD427B6264f9DdF05B5D14", Public: "0x28dA1beF8F5361863DcD427B6264f9DdF05B5D14", BLSKey: "478b9d46f45001853c8b4befc94f3d3bcc79769d047d1fa17b67af4a739da3e"}, + {Address: "0xfdc963E875Ea99E434e4B815b7d8Bf506dAA9222", Public: "0xfdc963E875Ea99E434e4B815b7d8Bf506dAA9222", BLSKey: "62f20a140c27318050edbaece0194ef383e008dc403a8362ea8a87bd62a79cf3"}, + {Address: "0xC6b6a71d6f0C5b98E25FCf14b5378c807B0d475a", Public: "0xC6b6a71d6f0C5b98E25FCf14b5378c807B0d475a", BLSKey: "37df0b60c13e2fcd0a4ffb93abd98495ba91ec02cb1e0c6a2ba654c81959a67e"}, + {Address: "0x880D5c6aD4117D26126543Af48f2f9bCDd4DaA0A", Public: "0x880D5c6aD4117D26126543Af48f2f9bCDd4DaA0A", BLSKey: "46d3ef05731b7d3937cb9f628525f8ff777e3f4832c5244c9aaeb187277cf217"}, + {Address: "0x631eF9cA4Cd625e0610e9808674284028Ad30662", Public: "0x631eF9cA4Cd625e0610e9808674284028Ad30662", BLSKey: "1f1c73b0a5a8655473abe0798a3c0d9d153bf5432acb1a3848aef8b4da69f58e"}, + {Address: "0x65324a6539e78e476AA1e08396bcA1a141C93938", Public: "0x65324a6539e78e476AA1e08396bcA1a141C93938", BLSKey: "69e293dbddcb5c0b86d41afca89bfd958b01c220046ea76db57b36ea2fd13fa3"}, + {Address: "0x695F372E04A79CCed0857cCB0364CC229b944C8C", Public: "0x695F372E04A79CCed0857cCB0364CC229b944C8C", BLSKey: "254556d6392bd78ec71b791312755172644f5061fa5b96c51e885e980fea3d86"}, +} diff --git a/internal/genesis/genesis.go b/internal/genesis/genesis.go new file mode 100644 index 000000000..0833708ff --- /dev/null +++ b/internal/genesis/genesis.go @@ -0,0 +1,89 @@ +package genesis + +import ( + "crypto/ecdsa" + "fmt" + "os" + "strings" + + "github.com/ethereum/go-ethereum/crypto" + "github.com/harmony-one/harmony/internal/utils" +) + + +const genesisString = "https://harmony.one 'Open Consensus for 10B' 2019.06.01 $ONE" + +// DeployAccount is the account used in genesis +type DeployAccount struct { + Address string // account address + Public string // account public key + BLSKey string // account private BLS key (To be removed) + ShardID uint32 // shardID of the account +} + +func (d DeployAccount) String() string { + return fmt.Sprintf("%s/%s/%s:%d", d.Address, d.Public, d.BLSKey, d.ShardID) +} + +// BeaconAccountPriKey is the func which generates a constant private key. +func BeaconAccountPriKey() *ecdsa.PrivateKey { + prikey, err := ecdsa.GenerateKey(crypto.S256(), strings.NewReader(genesisString)) + if err != nil && prikey == nil { + utils.GetLogInstance().Error("Failed to generate beacon chain contract deployer account") + os.Exit(111) + } + return prikey +} + +// FindAccount find the DeployAccount based on the account address, and the account index +// the account address could be from GenesisAccounts or from GenesisFNAccounts +// the account index can be used to determin the shard of the account +func FindAccount(address string) (int, *DeployAccount) { + for i, acc := range GenesisAccounts { + if address == acc.Address { + return i, &acc + } + } + for i, acc := range GenesisFNAccounts { + if address == acc.Address { + return i, &acc + } + } + return 0, nil +} + +// GenesisBeaconAccountPriKey is the private key of genesis beacon account. +var GenesisBeaconAccountPriKey = BeaconAccountPriKey() + +// GenesisBeaconAccountPublicKey is the private key of genesis beacon account. +var GenesisBeaconAccountPublicKey = GenesisBeaconAccountPriKey.PublicKey + +// DeployedContractAddress is the deployed contract address of the staking smart contract in beacon chain. +var DeployedContractAddress = crypto.CreateAddress(crypto.PubkeyToAddress(GenesisBeaconAccountPublicKey), uint64(0)) + +// GenesisAccounts are the accounts for the initial genesis nodes hosted by Harmony. +var GenesisAccounts = [...]DeployAccount{ + // 0-9 + {Address: "0x007579ED2Fe889C5255C36d4978Ac94d25811771", Public: "0x007579ED2Fe889C5255C36d4978Ac94d25811771", BLSKey: "66acb3a7c990be4b06709058fdef8122b7ecdbaf023e56ccf8cdf671c5333646"}, + {Address: "0x00F98965458a35f3788C45A095582AB18A5ae79c", Public: "0x00F98965458a35f3788C45A095582AB18A5ae79c", BLSKey: "5e9e2fffbf7cfad085d7b0147d2acd680cfd8b8d62daa9c39370185ba0207920"}, + {Address: "0x0102B41674C3ac2634f404d8c25C25Bb959fE952", Public: "0x0102B41674C3ac2634f404d8c25C25Bb959fE952", BLSKey: "56714bb94188c335d1243fa3d17fd50ff63a1a9bf740faecd97996f3a0737e87"}, + {Address: "0x0178A7bE4399c1968156edE4f52ae91953ab9B63", Public: "0x0178A7bE4399c1968156edE4f52ae91953ab9B63", BLSKey: "3de4fbe27f453b254014094108bf11b0a2ba4144585bf4cb10332155476339e9"}, + {Address: "0x0215c51A3d67Eb1e949bD1Df8b74D3aef097e92d", Public: "0x0215c51A3d67Eb1e949bD1Df8b74D3aef097e92d", BLSKey: "18c62ae8cd2a37e50b8fc89c53458ad6d9482f413d50086199d309ad1062684c"}, + {Address: "0x021983eA41fbeeB39F82a9CAf1A83476F0cFeEDC", Public: "0x021983eA41fbeeB39F82a9CAf1A83476F0cFeEDC", BLSKey: "2ca85157154a7df9fcdb4a404c7a8ac0675bbff7e841237b0de4645a9dcaca1c"}, + {Address: "0x03d1a55eA1246efB257D49D9286f7D370bd09c97", Public: "0x03d1a55eA1246efB257D49D9286f7D370bd09c97", BLSKey: "1dc77bb20378c7cacf82dd6fb7d5dedbb2c0855d85e0eb2d7d6df05bbb5da65d"}, + {Address: "0x055b95d5205B5711099C32626Ea61481779a2233", Public: "0x055b95d5205B5711099C32626Ea61481779a2233", BLSKey: "185bcaede728332c088645b31b988404512eeeb02413360cac6e30c9ca002661"}, + {Address: "0x0566729A6FCDda16287777baB5D4425AA93bB0Fc", Public: "0x0566729A6FCDda16287777baB5D4425AA93bB0Fc", BLSKey: "18b5d0d89b4575e002e4fd41e46fa628a248e1caa55fa887acd3c446b89058e3"}, + {Address: "0x05bA7FcC4c1d7286f7A3d5552DdF305677338c22", Public: "0x05bA7FcC4c1d7286f7A3d5552DdF305677338c22", BLSKey: "2221983e3f69897d54fcaa3cb131f4c729592f1b10faf247c0772e7b6476c1fd"}, + + // 10-19 + {Address: "0x063893E8EfA148E29B914702AD6A9930d41C8F13", Public: "0x063893E8EfA148E29B914702AD6A9930d41C8F13", BLSKey: "4000ba626d897e76a9878922deb081cfd52af3fefc6f353a51fa32dad88a6cc4"}, + {Address: "0x06693dEE3d72a30075E7447b18c6f3ed8AE62174", Public: "0x06693dEE3d72a30075E7447b18c6f3ed8AE62174", BLSKey: "60b6b4326239eb330207d9b751cfcea620a41b02b9ca270ed8f1670a1ffa3f51"}, + {Address: "0x066B40c45D06eEFE8Bb8677fdaFdaC5C8dF9d09C", Public: "0x066B40c45D06eEFE8Bb8677fdaFdaC5C8dF9d09C", BLSKey: "605234f8ea10fd73c0588f0e1fb40821efb341eea20e76d8350a1029e5af2dbf"}, + {Address: "0x079C1FFEaa70Ebdd2F3235b2F82BeE0b1101f092", Public: "0x079C1FFEaa70Ebdd2F3235b2F82BeE0b1101f092", BLSKey: "4505d95f6045c8d2a00b923c583e82979e75a7b0c920ddf6f2af902c1ae37432"}, + {Address: "0x07Fe4B973008c53528142b719BdfaC428F81905b", Public: "0x07Fe4B973008c53528142b719BdfaC428F81905b", BLSKey: "3b5fcadb39db34f9bbd4381836dc43a8629b6e14a3eac0942fcb70540538467b"}, + {Address: "0x09531Cea52595bCe55329Be07f11Ad033B9814Ee", Public: "0x09531Cea52595bCe55329Be07f11Ad033B9814Ee", BLSKey: "3a315d1c8ede4b7f18ef51f8249ab2a414c910196f1b9995f9cce2d6d8aa2201"}, + {Address: "0x0B4B626c913a46138feD9d7201E187A751DFF485", Public: "0x0B4B626c913a46138feD9d7201E187A751DFF485", BLSKey: "13a71379a7cb13aefa0433428b080d1f2ed3ee475f30bf093c1bfd278c07d0d0"}, + {Address: "0x0CCa9111F4588EDB3c9a282faE233B830dE21A0D", Public: "0x0CCa9111F4588EDB3c9a282faE233B830dE21A0D", BLSKey: "6d543bbc84d0b4daa45c077ddfaaffa43343558e5cc5a1efde846c630170747f"}, + {Address: "0x0F595ed534b6464eB2C80A037FFba02D23AfdfD2", Public: "0x0F595ed534b6464eB2C80A037FFba02D23AfdfD2", BLSKey: "1283b83fe50dc548eaa5cf850adb8940f5eaaff30816ecd46e1c0a7a548f52fc"}, + {Address: "0x0a0b8c48e42c540078fD99004915Be265f380dB7", Public: "0x0a0b8c48e42c540078fD99004915Be265f380dB7", BLSKey: "488678864c4f2b7f3c80d83564f4f0521b26a81bb96be4fcf207a2d4b8dd2d7c"}, +} diff --git a/internal/genesis/genesis_test.go b/internal/genesis/genesis_test.go new file mode 100644 index 000000000..c89d7d4db --- /dev/null +++ b/internal/genesis/genesis_test.go @@ -0,0 +1,10 @@ +package genesis + +import ( + "testing" +) + +func TestString(t *testing.T) { + _ = BeaconAccountPriKey() +} + diff --git a/internal/genesis/newnodes.go b/internal/genesis/newnodes.go new file mode 100644 index 000000000..673348a97 --- /dev/null +++ b/internal/genesis/newnodes.go @@ -0,0 +1,15 @@ +package genesis + +// NewNodeAccounts are the accounts for the new node +var NewNodeAccounts = [...]DeployAccount { + {Address: "0x0e59b767D5E74cf7B29Ef9bEc3dA4c402d357C6C", Public: "0x0e59b767D5E74cf7B29Ef9bEc3dA4c402d357C6C", BLSKey: "60c398270c8122ae196f03b9bee10186f224f0fe378eefbdcdfd2240a52d46ef"}, + {Address: "0x0fAAda81c203C74CAc786786f7D428477a04bF9c", Public: "0x0fAAda81c203C74CAc786786f7D428477a04bF9c", BLSKey: "3ff0efdc6c88d21070721840da44cb2d381a6056d08bc2bc5552bfaafd3652b3"}, + {Address: "0x0fd228bdFbe9ad0c898e9A0Fee2E6FB01f596F0d", Public: "0x0fd228bdFbe9ad0c898e9A0Fee2E6FB01f596F0d", BLSKey: "34ef1d0db507afd5b59aa52c73cf2a46e25026a36592d83e561e07d618a10b4e"}, + {Address: "0x123FF831333e2662D00c60A2C46f7196204506e9", Public: "0x123FF831333e2662D00c60A2C46f7196204506e9", BLSKey: "517de2e70402bdcc8c6d8f3ff4993f4b409e8a925cf9c40dc72a88b231f8608"}, + {Address: "0x1240775288d0EE975583A2A7022006539dADb354", Public: "0x1240775288d0EE975583A2A7022006539dADb354", BLSKey: "3e463c1eafd23c6dec50b425dd6635763b74b51c971994ac651814fdd1715ce5"}, + {Address: "0x127b8Cb71Fb78338d9EFFe47bB51c2EAd3995378", Public: "0x127b8Cb71Fb78338d9EFFe47bB51c2EAd3995378", BLSKey: "1e9f19c02ecc4f39753d91262cfb0744f7ef590f23eebaba7ca88a6f28faf8d"}, + {Address: "0x141B0e0f05739B7B784654E973e9b9146473aAb9", Public: "0x141B0e0f05739B7B784654E973e9b9146473aAb9", BLSKey: "6ddc97eb5c8d7b64fda8e75c6bbe9f407bbafb84d1b73ad57b5eae5644557559"}, + {Address: "0x1492ebD0EcfD54B4c211b37C8891bA3493c52100", Public: "0x1492ebD0EcfD54B4c211b37C8891bA3493c52100", BLSKey: "3dd53a752ae9551e6b5047bcf17d0abb5a8161d254fb3fd7a19e52a7ab1bface"}, + {Address: "0x1530A04592F9C3bF06aC6044525f08937ED38edB", Public: "0x1530A04592F9C3bF06aC6044525f08937ED38edB", BLSKey: "62f20a140c27318050edbaece0194ef383e008dc403a8362ea8a87bd62a79cf3"}, + {Address: "0xE2ab78ecf325084485957B2599d53Bcf944Cbca8", Public: "0xE2ab78ecf325084485957B2599d53Bcf944Cbca8", BLSKey: "3d99ea18a9f0ffbfc031476e88d1f729629a561a9041f8441df1cd4e2ffbda4d"}, +}