src/main/java/toy/servers/ToyBaseServer.java
/*
    The only thing this method do is to check that a given subversion
    is valid with respect to itself.
     */
The only thing this method do is to check that a given subversion
is valid with respect to itself.
The only thing this method do is to check that a given subversion is valid with respect to itself .
private boolean validateSubChainVersion(Types.subChainVersion v, int forkPoint) {
        Blockchain subV = getEmptyBC();
        subV.addBlock(v.getV(0));
        for (int i = 0 ; i < v.getVList().size() ; i++ ) {
            Types.Block pb = v.getV(i);
            if (!BlockDS.verify(pb.getHeader().getM().getSender(), pb)) {
                logger.debug(format("[#%d-C[%d] #1] invalid sub chain version, block [height=%d] digital signature is invalid " +
                        "[fp=%d ; sender=%d]", getID(),channel, pb.getHeader().getHeight(), forkPoint, v.getSender()));
                return false;
            }
            if (subV.getHeight() > 0) {
                if (!validateBlockHash(v.getV(i - 1), pb)) {
                    logger.debug(format("[#%d-C[%d] #1] invalid sub chain version, block hash is invalid [height=%d] [fp=%d]",
                            getID(),channel, pb.getHeader().getHeight(), forkPoint));
                    return false;
                }
            }
            if (subV.getHeight() >= f) {
                if (!subV.validateBlockCreator(pb, f)) {
                    logger.debug(format("[#%d-C[%d]] invalid invalid sub chain version, block creator is invalid [height=%d] [fp=%d]",
                            getID(),channel, pb.getHeader().getHeight(), forkPoint));
                    return false;
                }
            }
            subV.addBlock(pb);
        }
        return true;
    }
private boolean validateSubChainVersion ( Types . subChainVersion v , int forkPoint ) { Blockchain subV = getEmptyBC ( ) ; subV . addBlock ( v . getV ( 0 ) ) ; for ( int i = 0 ; i < v . getVList ( ) . size ( ) ; i ++ ) { Types . Block pb = v . getV ( i ) ; if ( ! BlockDS . verify ( pb . getHeader ( ) . getM ( ) . getSender ( ) , pb ) ) { logger . debug ( format ( "[#%d-C[%d] #1] invalid sub chain version, block [height=%d] digital signature is invalid " + "[fp=%d ; sender=%d]" , getID ( ) , channel , pb . getHeader ( ) . getHeight ( ) , forkPoint , v . getSender ( ) ) ) ; return false ; } if ( subV . getHeight ( ) > 0 ) { if ( ! validateBlockHash ( v . getV ( i - 1 ) , pb ) ) { logger . debug ( format ( "[#%d-C[%d] #1] invalid sub chain version, block hash is invalid [height=%d] [fp=%d]" , getID ( ) , channel , pb . getHeader ( ) . getHeight ( ) , forkPoint ) ) ; return false ; } } if ( subV . getHeight ( ) >= f ) { if ( ! subV . validateBlockCreator ( pb , f ) ) { logger . debug ( format ( "[#%d-C[%d]] invalid invalid sub chain version, block creator is invalid [height=%d] [fp=%d]" , getID ( ) , channel , pb . getHeader ( ) . getHeight ( ) , forkPoint ) ) ; return false ; } } subV . addBlock ( pb ) ; } return true ; }
The only thing this method do is to check that a given subversion
is valid with respect to itself.
The only thing this method do is to check that a given subversion is valid with respect to itself .