Search in sources :

Example 1 with CfgNetP2p

use of org.aion.zero.impl.config.CfgNetP2p in project aion by aionnetwork.

the class AionHub method initializeHub.

private void initializeHub(CfgAion _cfgAion, AionBlockchainImpl _blockchain, PendingTxCallback pendingTxCallback, NetworkBestBlockCallback networkBestBlockCallback, TransactionBroadcastCallback transactionBroadcastCallback, boolean forTest) {
    this.cfg = _cfgAion;
    // load event manager before init blockchain instance
    loadEventMgr(forTest);
    registerBlockEvents();
    // the current unit tests require passing in a different repository instance
    // during normal execution we need to instantiate the repository
    // for this reason we pass in null when a new instance is required
    this.blockchain = _blockchain == null ? new AionBlockchainImpl(cfg, eventMgr, forTest) : _blockchain;
    try {
        this.blockchain.load(cfg.getGenesis(), genLOG);
    } catch (IllegalStateException e) {
        genLOG.error("Found database corruption, please re-import your database by using ./aion.sh -n <network> --redo-import", e);
        System.exit(SystemExitCodes.DATABASE_CORRUPTION);
    }
    this.startingBlock = this.blockchain.getBestBlock();
    if (blockchain.forkUtility.is040ForkActive(blockchain.getBestBlock().getNumber())) {
        TransactionTypeRule.allowAVMContractTransaction();
    }
    this.mempool = new AionPendingStateImpl(blockchain, cfg.getConsensus().getEnergyStrategy().getUpperBound(), cfg.getTx().getTxPendingTimeout(), cfg.getTx().getPoolBackup(), cfg.getTx().isSeedMode(), cfg.getTx().getPoolDump(), pendingTxCallback, networkBestBlockCallback, transactionBroadcastCallback, forTest);
    if (cfg.getTx().isSeedMode()) {
        genLOG.info("Seed node mode enabled!");
    }
    /*
         * p2p hook up start sync mgr needs to be initialed after loadBlockchain()
         * method
         */
    CfgNetP2p cfgNetP2p = this.cfg.getNet().getP2p();
    this.chainId = this.cfg.getNet().getId();
    // there are two p2p implementation , now just point to impl1.
    this.p2pMgr = new P2pMgr(AionLoggerFactory.getLogger(LogEnum.P2P.name()), AionLoggerFactory.getLogger(LogEnum.SURVEY.name()), this.chainId, Version.KERNEL_VERSION, this.cfg.getId(), cfgNetP2p.getIp(), cfgNetP2p.getPort(), this.cfg.getNet().getNodes(), cfgNetP2p.getDiscover(), cfgNetP2p.getMaxTempNodes(), cfgNetP2p.getMaxActiveNodes(), cfgNetP2p.getBootlistSyncOnly(), cfgNetP2p.getErrorTolerance());
    this.syncMgr = new SyncMgr(blockchain, p2pMgr, eventMgr, cfg.getSync().getShowStatus(), cfg.getSync().getShowStatistics(), cfg.getNet().getP2p().getMaxActiveNodes());
    ChainConfiguration chainConfig = new ChainConfiguration();
    this.propHandler = new BlockPropagationHandler(1024, this.blockchain, syncMgr.getSyncStats(), p2pMgr, chainConfig.createBlockHeaderValidator(), cfg.getNet().getP2p().inSyncOnlyMode(), apiVersion, mempool);
    registerCallback();
    if (!forTest) {
        p2pMgr.run();
    }
    if (!AionBlockchainImpl.enableFullSyncCheck) {
        this.pow = new AionPoW();
        this.pow.init(blockchain, mempool, eventMgr, syncMgr);
    }
    SelfNodeStatusCallback callback = new SelfNodeStatusCallback(p2pMgr);
    callback.updateBlockStatus(blockchain.getBestBlock().getNumber(), blockchain.getBestBlock().getHash(), blockchain.getTotalDifficulty());
    blockchain.setNodeStatusCallback(callback);
    blockchain.setBestBlockImportCallback(new BestBlockImportCallback(mempool));
}
Also used : AionPoW(org.aion.zero.impl.pow.AionPoW) AionPendingStateImpl(org.aion.zero.impl.pendingState.AionPendingStateImpl) IP2pMgr(org.aion.p2p.IP2pMgr) P2pMgr(org.aion.p2p.impl1.P2pMgr) CfgNetP2p(org.aion.zero.impl.config.CfgNetP2p) BlockPropagationHandler(org.aion.zero.impl.sync.handler.BlockPropagationHandler) SyncMgr(org.aion.zero.impl.sync.SyncMgr)

Example 2 with CfgNetP2p

use of org.aion.zero.impl.config.CfgNetP2p in project aion by aionnetwork.

the class ApiWeb3Aion method priv_p2pConfig.

public RpcMsg priv_p2pConfig() {
    CfgNetP2p p2p = CfgAion.inst().getNet().getP2p();
    JSONObject obj = new JSONObject();
    obj.put("localBinding", p2p.getIp() + ":" + p2p.getPort());
    return new RpcMsg(obj);
}
Also used : CfgNetP2p(org.aion.zero.impl.config.CfgNetP2p) JSONObject(org.json.JSONObject)

Example 3 with CfgNetP2p

use of org.aion.zero.impl.config.CfgNetP2p in project aion by aionnetwork.

the class ApiWeb3Aion method configNet.

// TODO: we can refactor these in the future to be in
// their respective classes, for now put the toJson here
private static JSONObject configNet() {
    CfgNet config = CfgAion.inst().getNet();
    JSONObject obj = new JSONObject();
    // begin base.net.p2p
    CfgNetP2p configP2p = config.getP2p();
    JSONObject p2p = new JSONObject();
    p2p.put("ip", configP2p.getIp());
    p2p.put("port", configP2p.getPort());
    p2p.put("discover", configP2p.getDiscover());
    p2p.put("errorTolerance", configP2p.getErrorTolerance());
    p2p.put("maxActiveNodes", configP2p.getMaxActiveNodes());
    p2p.put("maxTempNodes", configP2p.getMaxTempNodes());
    p2p.put("clusterNodeMode", configP2p.inClusterNodeMode());
    p2p.put("syncOnlyMode", configP2p.inSyncOnlyMode());
    // end
    obj.put("p2p", p2p);
    // begin base.net.nodes[]
    JSONArray nodeArray = new JSONArray();
    for (String n : config.getNodes()) {
        nodeArray.put(n);
    }
    // end
    obj.put("nodes", nodeArray);
    // begin base
    obj.put("id", config.getId());
    // end
    return obj;
}
Also used : JSONObject(org.json.JSONObject) CfgNetP2p(org.aion.zero.impl.config.CfgNetP2p) JSONArray(org.json.JSONArray) CfgNet(org.aion.zero.impl.config.CfgNet) Hex.toHexString(org.aion.util.conversions.Hex.toHexString)

Aggregations

CfgNetP2p (org.aion.zero.impl.config.CfgNetP2p)3 JSONObject (org.json.JSONObject)2 IP2pMgr (org.aion.p2p.IP2pMgr)1 P2pMgr (org.aion.p2p.impl1.P2pMgr)1 Hex.toHexString (org.aion.util.conversions.Hex.toHexString)1 CfgNet (org.aion.zero.impl.config.CfgNet)1 AionPendingStateImpl (org.aion.zero.impl.pendingState.AionPendingStateImpl)1 AionPoW (org.aion.zero.impl.pow.AionPoW)1 SyncMgr (org.aion.zero.impl.sync.SyncMgr)1 BlockPropagationHandler (org.aion.zero.impl.sync.handler.BlockPropagationHandler)1 JSONArray (org.json.JSONArray)1