匿名用户2021年11月30日
32阅读
所属分类Google Go、Web3、区块链
授权协议View license

作品详情

JSONRPCserver

INBGO

OfficialgolangimplementationoftheInsightChain

Building

First,youneedbothaGo(version1.10orlater)andaCcompiler.

makeginb

or,tobuildthefullsuiteofutilities:

makeallRunning

Goingthroughallthepossiblecommandlineflagsisoutofscopehere,butwe'veenumeratedafewcommonparametercombostogetyouuptospeedquicklyonhowyoucanrunyourownginbinstance.

FullnodeonthemainINBnetwork

ByfarthemostcommonscenarioispeoplewantingtosimplyinteractwiththeINBnetwork:createaccounts;transferfunds;Mortgageorrelease;deployandinteractwithcontracts.Forthisparticularuse-casetheuserdoesn'tcareaboutyears-oldhistoricaldata,sowecanfast-syncquicklytothecurrentstateofthenetwork.Todoso:

$ginbconsoleFullsupernodeonthemainINBnetwork

Ifyouwanttobeasupernodeandhavetherighttomine,youhavetogetsomeoneelse'svoteinadvanceandonlythe21nodeswiththehighestnumberofvoteshavethechance.

Ifyoumeettheaboveconditions,pleasecontinue.

Youneedtomakeyournodeidbeforeyoustartthenetwork.

$ginbnodekey[datadir]

Thereturnednodeid(asenodes.id)needstobeconfiguredinthegenesis.jsonfile,aswellasyourip,port,name,countryandsoon.DataprovidesomeotherK-Vinformationifyouwanttostore

{"config":{"chainId":891,"homesteadBlock":0,"eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"vdpos":{"period":3,"signerPeriod":3,"signerBlocks":6,"epoch":201600,"maxSignersCount":21,"minVoterBalance":1000000000000000000,"genesisTimestamp":1561544470,"signers":["0x891b2388ce73356917b21ca54f3039cbdfc29313","0x4643ce2d6d4fe02e2b57070806364dde9eb8cac9","0x230cf5081833c4f16e69e102ea00a4583a33cb11"],"enodes":[{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},]}},"coinbase":"0x0000000000000000000000000000000000000000","difficulty":"0x1","extraData":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","gasLimit":"0x2fefd8","nonce":"0x0","mixHash":"0x0000000000000000000000000000000000000000000000000000000000000000","parentHash":"0x0000000000000000000000000000000000000000000000000000000000000000","timestamp":"0x00","alloc":{"891b2388ce73356917b21ca54f3039cbdfc29313":{"balance":"0"},"4643ce2d6d4fe02e2b57070806364dde9eb8cac9":{"balance":"0"},"230cf5081833c4f16e69e102ea00a4583a33cb11":{"balance":"0"}}}

Vdposisnecessary.Periodrepresentsthenumberofsecondsbetweenblocks,signerPeriodrepresentsthenumberofsecondsblocksbetweentwosupernodes,signerBlocksrepresentsthenumberofpackagedblockspersupernode,epochrepresentstheintervalbetweenemptyingvotinginformationandre-voting,andmaxSignersCountrepresentsthemaximumnumberofsupernodes.Enodesrepresentsinformationaboutallsupernodesthatwerefirstvotedforandeveryoneautomaticallyconnectstothesupernodes'networks.

Tip:TheneveryoneinitializestheGenesisBlockwiththesamesetofgenesis.jsonfiles

$ginbinitpath/to/genesis.json

Finallystartthenetwork

$ginb--datadirdata1/--networkid891--nodiscover--rpcport6002--port30002consoleFullnodeontheINBtestnetwork

Transitioningtowardsdevelopers,ifyou'dliketoplayaroundwithcreatingINBcontracts,youalmostcertainlywouldliketodothatwithoutanyrealmoneyinvolveduntilyougetthehangoftheentiresystem.Inotherwords,insteadofattachingtothemainnetwork,youwanttojointhetestnetworkwithyournode,whichisfullyequivalenttothemainnetwork,butwithplay-inberonly.

$ginb--testnetconsole

Theconsolesubcommandhastheexactsamemeaningasaboveandtheyareequallyusefulonthetestnettoo.Pleaseseeabovefortheirexplanationsifyou'veskippedhere.

Specifyingthe--testnetflag,however,willreconfigureyourginbinstanceabit:

Insteadofusingthedefaultdatadirectory(~/.inbonLinuxforexample),ginbwillnestitselfoneleveldeeperintoatestnetsubfolder(~/.inb/testnetonLinux).Note,onOSXandLinuxthisalsomeansthatattachingtoarunningtestnetnoderequirestheuseofacustomendpointsinceginbattachwilltrytoattachtoaproductionnodeendpointbydefault.E.g.ginbattach<datadir>/testnet/ginb.ipc.Windowsusersarenotaffectedbythis.InsteadofconnectingthemainINBnetwork,theclientwillconnecttothetestnetwork,whichusesdifferentP2Pbootnodes,differentnetworkIDsandgenesisstates.

Note:Althoughtherearesomeinternalprotectivemeasurestopreventtransactionsfromcrossingoverbetweenthemainnetworkandtestnetwork,youshouldmakesuretoalwaysuseseparateaccountsforplay-moneyandreal-money.Unlessyoumanuallymoveaccounts,ginbwillbydefaultcorrectlyseparatethetwonetworksandwillnotmakeanyaccountsavailablebetweenthem.

###ConfigurationAsanalternativetopassingthenumerousflagstothe`ginb`binary,youcanalsopassaconfigurationfilevia:```shell$geinb--config/path/to/your_config.toml

Togetanideahowthefileshouldlooklikeyoucanusethedumpconfigsubcommandtoexportyourexistingconfiguration:

$ginb--your-favourite-flagsdumpconfigProgrammaticallyinterfacingginbnodes

Asadeveloper,soonerratherthanlateryou'llwanttostartinteractingwithginbandtheInsightnetworkviayourownprogramsandnotmanuallythroughtheconsole.Toaidthis,ginbhasbuilt-insupportforaJSON-RPCbasedAPIsand[ginbspecificAPIs]ThesecanbeexposedviaHTTP,WebSocketsandIPC(UNIXsocketsonUNIXbasedplatforms,andnamedpipesonWindows).

TheIPCinterfaceisenabledbydefaultandexposesalltheAPIssupportedbyginb,whereastheHTTPandWSinterfacesneedtomanuallybeenabledandonlyexposeasubsetofAPIsduetosecurityreasons.Thesecanbeturnedon/offandconfiguredasyou'dexpect.

HTTPbasedJSON-RPCAPIoptions:

--rpcEnabletheHTTP-RPCserver--rpcaddrHTTP-RPCserverlisteninginterface(default:localhost)--rpcportHTTP-RPCserverlisteningport(default:8545)--rpcapiAPI'sofferedovertheHTTP-RPCinterface(default:inb,net,web3)--rpccorsdomainCommaseparatedlistofdomainsfromwhichtoacceptcrossoriginrequests(browserenforced)--wsEnabletheWS-RPCserver--wsaddrWS-RPCserverlisteninginterface(default:localhost)--wsportWS-RPCserverlisteningport(default:8546)--wsapiAPI'sofferedovertheWS-RPCinterface(default:inb,net,web3)--wsoriginsOriginsfromwhichtoacceptwebsocketsrequests--ipcdisableDisabletheIPC-RPCserver--ipcapiAPI'sofferedovertheIPC-RPCinterface(default:admin,debug,inb.vdpos,miner,net,personal,shh,txpool,web3)--ipcpathFilenameforIPCsocket/pipewithinthedatadir(explicitpathsescapeit)

You'llneedtouseyourownprogrammingenvironments'capabilities(libraries,tools,etc)toconnectviaHTTP,WSorIPCtoaginbnodeconfiguredwiththeaboveflagsandyou'llneedtospeakJSON-RPConalltransports.Youcanreusethesameconnectionformultiplerequests!

Note:PleaseunderstandthesecurityimplicationsofopeningupanHTTP/WSbasedtransportbeforedoingso!HackersontheinternetareactivelytryingtosubvertInsightnodeswithexposedAPIs!Further,allbrowsertabscanaccesslocallyrunningwebservers,somaliciouswebpagescouldtrytosubvertlocallyavailableAPIs!

Operatingaprivatenetwork

Maintainingyourownprivatenetworkismoreinvolvedasalotofconfigurationstakenforgrantedintheofficialnetworksneedtobemanuallysetup.

Definingtheprivategenesisstate

First,you'llneedtocreatethegenesisstateofyournetworks,whichallnodesneedtobeawareofandagreeupon.ThisconsistsofasmallJSONfile(e.g.callitgenesis.json):

{"config":{"chainId":891,"homesteadBlock":0,"eip155Block":0,"eip158Block":0,"byzantiumBlock":0,"vdpos":{"period":3,"signerPeriod":3,"signerBlocks":6,"epoch":201600,"maxSignersCount":21,"minVoterBalance":1000000000000000000,"genesisTimestamp":1561544470,"signers":["0x891b2388ce73356917b21ca54f3039cbdfc29313","0x4643ce2d6d4fe02e2b57070806364dde9eb8cac9","0x230cf5081833c4f16e69e102ea00a4583a33cb11"],"enodes":[{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},{"address":"0x891b2388ce73356917b21ca54f3039cbdfc29313","id":"327d1a41974ad0a672d9b3dcfada5a934b4c21207e95a40d534bde44c2f7b39c4f10dda7a7bc060c00868a77b522878ab960dff2f23f463616736a1e6e39ea93","ip":"192.168.1.181","port":"30001","name":"inb","nation":"China","city":"beijing","image":"www.image.com","website":"www.insightchain.io","email":"insightchain@xx.com","data":"{\"hobby\":\"money\",\"age\":\"21\"}"},]}

Theabovefieldsshouldbefineformostpurposes,althoughwe'drecommendchangingthenoncetosomerandomvaluesoyoupreventunknownremotenodesfrombeingabletoconnecttoyou.Ifyou'dliketopre-fundsomeaccountsforeasiertesting,youcanpopulatetheallocfieldwithaccountconfigs:

"alloc":{"0x0000000000000000000000000000000000000001":{"balance":"111111111"},"0x0000000000000000000000000000000000000002":{"balance":"222222222"}}

WiththegenesisstatedefinedintheaboveJSONfile,you'llneedtoinitializeeveryginbnodewithitpriortostartingituptoensureallblockchainparametersarecorrectlyset:

$ginbinitpath/to/genesis.jsonCreatingtherendezvouspoint

Withallnodesthatyouwanttoruninitializedtothedesiredgenesisstate,you'llneedtostartabootstrapnodethatotherscanusetofindeachotherinyournetworkand/orovertheinternet.Thecleanwayistoconfigureandrunadedicatedbootnode:

$bootnode--genkey=boot.key$bootnode--nodekey=boot.key

Note:Youcouldalsouseafull-fledgedginbnodeasabootnode,butit'sthelessrecommendedway.

Startingupyourmembernodes

Withthebootnodeoperationalandexternallyreachable(youcantrytelnet<ip><port>toensureit'sindeedreachable),starteverysubsequentginbnodepointedtothebootnodeforpeerdiscoveryviathe--bootnodesflag.Itwillprobablyalsobedesirabletokeepthedatadirectoryofyourprivatenetworkseparated,sodoalsospecifyacustom--datadirflag.

$ginb--datadir=path/to/custom/data/folder--bootnodes=<bootnode-enode-url-from-above>

Note:Sinceyournetworkwillbecompletelycutofffromthemainandtestnetworks,you'llalsoneedtoconfigureaminertoprocesstransactionsandcreatenewblocksforyou.

Runningaprivateminer

MiningonthepublicInsightnetworkisacomplextaskasit'sonlyfeasibleusingGPUs,requiringanOpenCLorCUDAenabledinbminerinstance.Forinformationonsuchasetup

Inaprivatenetworksetting,howeverasingleCPUminerinstanceismorethanenoughforpracticalpurposesasitcanproduceastablestreamofblocksatthecorrectintervalswithoutneedingheavyresources(considerrunningonasinglethread,noneedformultipleoneseither).Tostartaginbinstanceformining,runitwithallyourusualflags,extendedby:

$ginb<usual-flags>--mine--minerthreads=1--inberbase=0x0000000000000000000000000000000000000000
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论